Disable order email notification if a specific product is purchased in WooCommerce

Disable order email notification if a specific product is purchased in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

add_action( 'woocommerce_product_query', 'wc_sale_category' );
 
function filter_woocommerce_email_recipient_new_order( $recipient, $order, $email ) {
    // Avoiding backend displayed error in WooCommerce email settings
    if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
    
    // Loop through order items
    foreach ( $order->get_items() as $key => $item ) {
        // Product ID
        $product_id = $item->get_variation_id() > 0 ? $item->get_variation_id() : $item->get_product_id();

        // Product ID occurs and count is equal to 1
        if ( in_array( $product_id, array( 5274 ) ) && count( $order->get_items() ) == 1 ) {
            $recipient = '';
            break;
        }
    }

    return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order', 'filter_woocommerce_email_recipient_new_order', 10, 3 );

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.