1
votes

In Woocommerce, I need to stop email notifications sent to the customer when order place except when payment_method is BACS (Direct bank transfer).

I tried following in my active theme's function.php file:

add_filter( 'woocommerce_email_recipient_customer_on_hold_order_order', 'customer_order_email_if_bacs', 10, 2 );

function customer_order_email_if_bacs( $recipient, $order ) {

    if( $order->payment_method() !== 'bacs' ) $recipient = '';

    return $recipient;
}

But it don't work. Any help is appreciated.

1

1 Answers

1
votes

Update 2

The woocommerce_email_recipient_{$email_id} filter is a composite hook and the right email ID to set in it is customer_on_hold_order and not customer_on_hold_order_order which will not work…

With the WC_Order object, since Woocommerce 3, you need to use get_payment_method() method.

To avoid Customer ON Hold email notification except for "Bacs" payment method use:

add_filter( 'woocommerce_email_recipient_customer_on_hold_order', 'customer_on_hold_order_for_bacs', 10, 2 );
function customer_on_hold_order_for_bacs( $recipient, $order ) {

    if( is_a('WC_Order', $order) && $order->get_payment_method() !== 'bacs' ){
        $recipient = '';
    }
    return $recipient;
}

Code goes in function.php file of your active child theme (active theme). Tested and works.