WooCommerce: Send Email When a Coupon Is Used

Coupons are often more than just discounts. They can represent affiliate partnerships, internal promotions, manual workflows, or campaigns that need tracking beyond basic WooCommerce reports. Yet, by default, WooCommerce doesn’t notify anyone when a coupon is actually redeemed in an order.

This code snippet solves that gap by sending a custom email whenever a specific coupon is used at checkout. You can notify an affiliate that their code was redeemed, alert yourself as the admin for tracking purposes, or inform a store manager that a manual action is required after purchase. The logic is simple, lightweight, and hooks directly into the “order complete” process, so it runs only when it matters.

Because it’s fully customizable, you can target one coupon or multiple coupons, change recipients dynamically, and tailor the email content to your workflow. If you rely on coupons as signals rather than just discounts, this snippet gives you immediate visibility without adding plugins or external services.

Coupon used is “j10” in this case. The code below can help you email someone if the order contains such a coupon!

PHP Snippet: Email Custom Recipient When Order With Coupon is Marked as Completed

/**
 * @snippet       Email someone if WooCommerce order contains a given coupon
 * @tutorial      https://fa8faab2-7736-467b-aa28-860b32869022.express.conves.io/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 10
 * @community     Join https://fa8faab2-7736-467b-aa28-860b32869022.express.conves.io/club/
 */

add_action( 'woocommerce_order_status_completed', 'bb_email_on_coupon_used' );

function bb_email_on_coupon_used( $order_id ) {
    if ( ! $order_id ) {
        return;
    }
    $order = wc_get_order( $order_id );
    if ( ! $order ) {
        return;
    }
    foreach ( $order->get_used_coupons() as $coupon_code ) {
        if ( strtolower( $coupon_code ) === 'xyz123' ) { // COUPON CODE
            $to = 'test@example.com';
            $subject = 'Referral Earned!';
            $message = sprintf(
                "Hi there,\n\nOrder #%d has been completed with coupon 'xyz123'.\n\nCustomer: %s\n\nTotal: %s\n\n",
                $order->get_id(),
                $order->get_billing_first_name(),
                $order->get_currency() . $order->get_total() 
            );
            $headers = array( 'Content-Type: text/plain; charset=UTF-8' );
            wp_mail( $to, $subject, $message, $headers );
            break;
        }
    }
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *