Easily display Woocommerce order coupon codes on thank you page, confirmation emails and order information with PHP snippet

Discover how to easily display the coupon codes used in a Woocommerce order on the thank you page (TYP), customer and admin confirmation emails and in the admin order information with a simple PHP snippet.

PHP snippet to show coupon code on Woocommerce thank you page, order emails and order info

There are many ways to do this, however, I have found that the easiest and simplest way is to add the coupon codes as a new row in the totals table using the woocommerce_get_order_item_totals hook.

Here is the PHP snippet to show the coupon codes used on an order as a totals row:

function mn_add_row_to_order_details( $total_rows, $order ) {
	if( $order->get_coupon_codes() ) {
		$coupon_codes = '';

		foreach( $order->get_coupon_codes() as $coupon ) {
			$coupon_codes .= '<span class="mn-coupon-code">' . $coupon . '</span>, ';
		$total_rows['coupon_codes'] = array(
		   'label' => __( 'Coupon codes used:', 'woocommerce' ),
		   'value'   => substr( $coupon_codes, 0, -2 )

	return $total_rows;

add_filter( 'woocommerce_get_order_item_totals', 'mn_add_row_to_order_details', 10, 2 );

As you can see, the class on every coupon code in the snippet lets you style the coupon codes like you want in the various places, whether it be for the customers or the admins.

Hope this helps!

If you have any questions, please let me know.


Similar Posts