There are times when you sell free products to give customers access to a membership, an online course, or for other reasons. In this cases, 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
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    Woo 3.8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
// 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', 'bbloomer_disable_customer_order_email_if_free', 10, 2 );
 
function bbloomer_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;
}
Share:

Leave a Reply