Add the below code at the end of your theme’s functions.php file or you can also add the below code inside your site-specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/** * Send an email each time an order with coupon(s) is completed * The email contains coupon(s) used during checkout process * */ function woo_email_order_coupons( $order_id ) { $order = new WC_Order( $order_id ); if( $order->get_used_coupons() ) { $subject = 'New Order Completed'; $message = 'A new order has been completed.\n'; $message .= 'Order ID: '.$order_id.'\n'; $message .= 'Coupons used:\n'; foreach( $order->get_used_coupons() as $coupon) { $message .= $coupon.'\n'; } @wp_mail( $to, $subject, $message, $headers ); } } add_action( 'woocommerce_thankyou', 'woo_email_order_coupons' ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.