How can (or with the help of which plug-in) in Woocommerce you can organize the sending of a coupon code if the user has bought for a certain amount?

    2 answers 2

    Add such code in the function.php of your theme.

    function action_woocommerce_order_status_completed_notification( $order_id, $order = false ) { $limit = 999; $total = $order->get_total(); if ( $total > $limit ) { $a=1; // Отправьте почту здесь } }; add_action( 'woocommerce_order_status_completed_notification', 'action_woocommerce_order_status_completed_notification', 10, 2 ); 

    Set your value for $limit .

      Found a solution

       add_action( 'woocommerce_thankyou', 'wc_free_spa_voucher_email_notification', 10, 1 ); function wc_free_spa_voucher_email_notification( $order_id ) { if ( ! $order_id ) return; $order = wc_get_order( $order_id ); $current_subtotal = $order->get_subtotal(); //current order's subtotal $current_total = $order->get_total(); //current order's total $min_amount = 600; //min amount to spend to get free voucher if ($current_subtotal >= $min_amount) { $user_complete_name_and_email = $order->billing_first_name . ' <' . $order->billing_email . '>'; $to = $user_complete_name_and_email; $today = date("j"); $thisMonth = date("n"); $thisYear = date("Y"); $validityDate = date("F j", mktime(0,0,0, $thisMonth+1, $today, $thisYear)); $headers = 'From: Upscale and Posh Flowers <customercare@upscaleandposh.com>' . "\r\n"; // Sending a custom email when 'Cash on delivery' is the payment method. if ( get_post_meta($order->id, '_payment_method', true) == 'cod' ) { $subject = 'Your Massage FREE Voucher. Take it!'; //$message = 'Voucher code: spa_2017 (Cash on delivery)'; $message = 'My Msg'; } else { $subject = 'Your Massage FREE Voucher. Take it!'; //$message = 'Voucher code: spa_2017'; $message = 'My Msg'; } //end if - check what kind of payment type if( $subject & $message) { add_filter( 'wp_mail_content_type','wpse27856_set_content_type' ); wp_mail($to, $subject, $message, $headers ); remove_filter( 'wp_mail_content_type','wpse27856_set_content_type' ); } // send voucher mail } // check if order's subtotal reach AED 600 else { return; } 

      }