1

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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Felipe SooUl
  • 71
  • 1
  • 7

1 Answers1

4

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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • The first code seems to work, but I'm not receiving a New order e-mail when the status changes to "Processing". Is there a way to enable the New Order e-mail only at Processing Status? – Felipe SooUl Feb 06 '21 at 00:49
  • When the order goes from "Pending Payment" to "Processing", I'm receiving the e-mail admin e-mail. But, when goes from "On Hold" to "Processing", I don't get the New Order e-mail. – Felipe SooUl Feb 06 '21 at 01:05
  • 1
    @FelipeSooUl First, I remember that you didn't provide any code attempt in your question, which is the rule on StackOverFlow. Next time, Just add a comment without removing answer acceptance and be patient… If I don't solve the problem after some time, you can remove acceptance. – LoicTheAztec Feb 06 '21 at 10:52
  • Oh, I'm sorry for removing the answer acceptance. I'm kinda new at stack overflow, so I'm still learning some stuff about WordPress / Woocommerce. I'll test the code tonight. Thank you so much for your support, @LoicTheAztec. – Felipe SooUl Feb 06 '21 at 12:17
  • Hi @LoicTheAztec - after using the snippet you provided and replacing `return = $order->get_status() === 'on-hold' ? '' : $recipient;` with `return = $order->get_status() === 'processing' ? $recipient : '';` an error was returned. I believe what you meant to write was `return $order->get_status() === 'processing' ? $recipient : '';` – David Sep 09 '21 at 07:43