Stop specific customer email notification based on payment methods in Woocommerce

こ雲淡風輕ζ 提交于 2019-12-08 04:55:49

问题


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:


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.



来源:https://stackoverflow.com/questions/53361845/stop-specific-customer-email-notification-based-on-payment-methods-in-woocommerc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!