問題描述
在 Woocommerce 中,我需要在下訂單時停止向客戶發送電子郵件通知,除非 Payment_method 是 BACS(直接銀行轉賬).
In Woocommerce, I need to stop email notifications sent to the customer when order place except when payment_method is BACS (Direct bank transfer).
我嘗試在我的活動主題的 function.php 文件中執行以下操作:
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.
推薦答案
更新 2
woocommerce_email_recipient_{$email_id}
過濾器是一個復合鉤子,在其中設置的正確電子郵件 ID 是 customer_on_hold_order
而不是 customer_on_hold_order_order
不會工作......
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…
使用 WC_Order
對象,從 Woocommerce 3 開始,您需要使用 get_payment_method()
方法.
With the WC_Order
object, since Woocommerce 3, you need to use get_payment_method()
method.
為了避免使用Bacs"付款方式之外的客戶保留電子郵件通知:
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;
}
代碼位于您的活動子主題(活動主題)的 function.php 文件中.經測試有效.
Code goes in function.php file of your active child theme (active theme). Tested and works.
這篇關于根據 Woocommerce 中的付款方式停止特定客戶的電子郵件通知的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!