Menu Close

WooCommerce: Don’t Send Emails for Free Orders

default

There are times when you sell free products to give customers access to a membership, an online course, or for other reasons. In these cases, you might not want to send the “Order Completed” email or get the “New Order” transactional notification, so that you can avoid sending and receiving hundreds of emails.

Of course, you’d still want to keep the order emails for amounts above $0. Here’s the fix.

WooCommerce: disable order emails if total is 0

PHP Snippet: Disable WooCommerce Order Emails If Total = 0

/**
 * @snippet       Disable Emails for Free Orders - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
// To target additional emails you can add EMAIL_ID to this filter:
// "woocommerce_email_recipient_EMAIL_ID"
// Find EMAIL_ID: businessbloomer.com/woocommerce-add-extra-content-order-email
 
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'bbloomer_disable_order_email_if_free', 9999, 2 );
add_filter( 'woocommerce_email_recipient_new_order', 'bbloomer_disable_order_email_if_free', 9999, 2 );
 
function bbloomer_disable_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;
}
View Source
Posted in WooCommerce Tips