Disable the order completed email for specific products in WooCommerce

Disable the order completed email for specific products in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

function filter_woocommerce_email_recipient_new_order( $recipient, $order ) {
    // 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( 111 ) ) && count( $order->get_items() ) == 1 ) {
            $recipient = '';
            break;
        }
    }

    return $recipient;
}
add_filter( 'woocommerce_email_recipient_customer_completed_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.