Search code examples
phpwordpresswoocommerceordersemail-notifications

Disable WooCommerce New order email notification if order status is On hold


Is there a way to disable the "New Order" e-mail notification sent to admin when the order status is "On hold"?

Or to enable it only for "processing" status?

I also tried different things to receive the "New Order" email only when the status is "Processing", without success.

Any help.


Solution

  • Updated

    To disable "New Order" e-mail notification sent to admin when the order status is "on-hold", use:

    add_filter( 'woocommerce_email_recipient_new_order', 'disable_new_order_for_on_hold_order_status', 10, 2 );
    function disable_new_order_for_on_hold_order_status( $recipient, $order = false ) {
        if ( ! $order || ! is_a( $order, 'WC_Order' ) ) 
            return $recipient;
    
        return $order->get_status() === 'on-hold' ? '' : $recipient;
    }
    

    To enable "New Order" e-mail notification sent to admin only when order status is "processing" replace in the function above:

    return = $order->get_status() === 'on-hold' ? '' : $recipient;
    

    with the following:

    return = $order->get_status() === 'processing' ? $recipient : '';
    

    Code goes in functions.php file of the active child theme (or active theme). Tested and works.