Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins

How to Add Coupons Used by Customers to WooCommerce Order Ids?

This powerful customization is for store owners who love running promotions and discounts! Imagine being able to instantly see which orders benefited from your latest coupon campaigns. This feature lets you do just that by appending coupon details to WooCommerce Order IDs. Curious how it works? Dive into our full post to discover the coupons used during a checkout process just by checking the admin Orders page.

Solution: Add Coupons Used by Customers to WooCommerce Order Ids

The code snippet will modify the default WooCommerce Order IDs and append it with the coupons used during checkout.

add_filter( 'woocommerce_order_number', 'ts_add_coupon_code_to_order_number', 10, 2 );

function ts_add_coupon_code_to_order_number( $order_number, $order ) {
    // Get the coupon code associated with the order
    $coupon_code = '';

    // Check if the order has applied coupons
    if ( $order->get_used_coupons() ) {
        // Get the first applied coupon code
        $coupon_codes = $order->get_used_coupons();
        $coupon_code = reset( $coupon_codes ); // Get the first coupon code

    // Append the coupon code to the order number
    $order_number_with_coupon = $order_number . '-' . $coupon_code;

    return $order_number_with_coupon;


The code looks for if the order has any applied coupons using the get_used_coupons() method of the WooCommerce order object. If coupons have been used, it retrieves the applied coupon code from the order and then concatenates the original order number with the coupon code.

How to Add Coupons Used by Customers to WooCommerce Order Ids? - Tyche Softwares

Similar to retriving coupons used in WooCommerce Orders , why not go a bit further and add payment methods to custom order numbers? This helps you fine-tune your sales strategies,optimize payment processing, reduce transaction fees, and create targeted promotions based on the most used payment methods.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x