2

In WooCommerce, How and where I can apply some code for New Order Email notification, where I should get the Applied Coupon Code display.

In the template for New Order Email notification I have @hooked WC_Emails::order_details() that shows the order details table…

Also is WC_Email::order_details() the exact hook which I am searching for to update coupon code in New order mail to admin?

I am loosed, any help will be really appreciated…

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Surabhi Gupta
  • 91
  • 2
  • 7

1 Answers1

4

The hook that you are searching is woocommerce_email_order_details action hook that can be used this way:

add_action( 'woocommerce_email_order_details', 'action_email_order_details', 10, 4 );
    function action_email_order_details( $order, $sent_to_admin, $plain_text, $email ) {
     if( $sent_to_admin ): // For admin emails notification

     // Your code goes HERE

     endif;
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.


In your function you can use any of the 4 arguments from the hook like $order the WC_Order object.

You can use the WC_Abstract_Order method get_used_coupons() that will give you an array of coupons codes used in the order, like:

// Get the array of coupons codes
$coupon_codes = $order->get_used_coupons();

// Convert and display the array in a coma separated string:
echo 'Coupon codes: ' . implode( ', ', $coupon_codes );
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399