Disable Customer Order Email for Free Orders

woocommerce disable custome

There are times when you sell free products to give customers access to a membership, an online course, or for other reasons. In this case, you might not want to send them the “Order Completed” email, as the follow-up work is done by your email marketing software or they are automatically redirected to the resource upon checkout.

Of course, you definitely want to keep the “Order Completed” emails for orders that are not $0. Unfortunately, the method suggested by WooCommerce which “unhooks the emails” cannot be used together with a conditional check (in our case we need to verify if the order total is $0), so a workaround is needed. Here’s the fix.

WooCommerce: disable a customer email if the order total is 0

PHP Snippet: Disable Customer Order Email for Free Orders – WooCommerce

/**
 * @snippet       Disable Customer Order Email for Free Orders - WooCommerce
 * @author        PHP Stackoverflow
 * @compatible    Woo 3.8
 */
 
// To target another email you can change the filter to e.g.:
// "woocommerce_email_recipient_customer_processing_order"
 
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'phpsof_disable_customer_order_email_if_free', 10, 2 );
 
function phpsof_disable_customer_order_email_if_free( $recipient, $order ) {
    $page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
    if ( 'wc-settings' === $page ) {
        return $recipient; 
    }
    if ( (float) $order->get_total() === '0.00' ) $recipient="";
    return $recipient;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before “?>” if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files.

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with the Storefront theme.

Leave a Reply

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