WooCommerce: display coupons used in an order in the confirmation email and on the edit page

Picture of Amitpal Singh
Amitpal Singh
October 8, 2021

add_action( 'woocommerce_email_after_order_table', 'add_payment_method_to_admin_new_order', 15, 2 );

/**
* Add used coupons to the order confirmation email
*
*/
function add_payment_method_to_admin_new_order( $order, $is_admin_email ) {

if ( $is_admin_email ) {

if( $order->get_used_coupons() ) {

$coupons_count = count( $order->get_used_coupons() );

echo '

' . __('Coupons used') . ' (' . $coupons_count . ')

';

echo '

' . __('Coupons used') . ': ';

$i = 1;
$coupons_list = '';

foreach( $order->get_used_coupons() as $coupon) {
$coupons_list .= $coupon;
if( $i < $coupons_count ) $coupons_list .= ', '; $i++; } echo '

Coupons used (' . $coupons_count . ') : ' . $coupons_list . '

';

} // endif get_used_coupons

} // endif $is_admin_email
}

add_action( 'woocommerce_admin_order_data_after_billing_address', 'custom_checkout_field_display_admin_order_meta', 10, 1 );

/**
* Add used coupons to the order edit page
*
*/
function custom_checkout_field_display_admin_order_meta($order){

if( $order->get_used_coupons() ) {

$coupons_count = count( $order->get_used_coupons() );

echo '

' . __('Coupons used') . ' (' . $coupons_count . ')

';

echo '

' . __('Coupons used') . ': ';

$i = 1;

foreach( $order->get_used_coupons() as $coupon) {
echo $coupon;
if( $i < $coupons_count ) echo ', '; $i++; } echo '

';
}

}

Share this post:

How to Attribute?

Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a 1st-century BC text by the Roman statesman and philosopher Cicero.
for Example: Website, Social Media, Blogs, ebooks , newsletter, etc.
Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a 1st-century BC text by the Roman statesman and philosopher Cicero.
Copied!

Got a Question? Check out our FAQ Section.

Your action, our appreciation

It encourage us to give you more valuable content on website.