0

I have tried everything, but can't seem to get this right.

I'm using the code from Disable WooCommerce New order email notification if order status is On hold

to only send New order email (admin) when order status is processing. But I want to include a second order status "partially_paid" (coming from at deposit plugin)

My code is:

    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() === 'processing, partially_paid' ? $recipient : '';
}

I have also tried with:'

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

None of them working.

Any help is highly appreciated. Thanks.

Thyregod
  • 3
  • 1

1 Answers1

0

In your first attempt you are checking a single string against the order status. And there is no such status as processing, partially_paid.

To check multiple values you can use an array like you did in your second attempt. But at the moment your are checking if the current order status is equal to the full array. Instead you will have to check if the current order status is in your array. Which you can do with the in_array() function.

return in_array( $order->get_status(), array( 'processing', 'partially_paid' ) ) ? $recipient : '';

You can boil down the filter to the following code:

add_filter( 'woocommerce_email_recipient_new_order', function( $recipient, $order, $email ) {  
    return in_array( $order->get_status(), array( 'processing', 'partially_paid' ) ) ? $recipient : ''; 
}, 10, 3 );
Terminator-Barbapapa
  • 3,063
  • 2
  • 5
  • 16
  • Thanks @Terminator-Barbapapa for your suggestion. My code looks like this now, **but do not work.**: `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 in_array( $order->get_status(), array( 'processing', 'partially_paid' ) ) ? $recipient : ''; }` How will the full code look like? Best regards – Thyregod Oct 12 '22 at 11:49
  • See my updated answer. This will only send the new order email when the order status is either processing or partially_paid. If this is not working check if the filter is actually being called, and check if the slug of your custom order status is actually partially_paid. I've tested the filter locally and it works without issues for me. – Terminator-Barbapapa Oct 12 '22 at 20:37
  • Hi again, I can confirm this is working. However this conflicts somehow with the backend "Admin - WooCommerce - Settings - Emails." Only the new order email is showing in my backend. ? Any idea? @Terminator-Barbapapa – Thyregod Oct 13 '22 at 09:08
  • This filter only deals with the recipient. It does not change available emails. So I think that is a different issue. – Terminator-Barbapapa Oct 15 '22 at 11:52
  • If the above answer solves your initial question please mark it as accepted (and possibly vote it up). Thank you in advance! – Terminator-Barbapapa Oct 17 '22 at 07:28