我想停止发送特定用户/电子邮件的WooCommerce电子邮件。这是我在订单完成后停止发送电子邮件的示例代码。
<?php
add_filter( 'woocommerce_email_headers', 'ieo_ignore_function', 10, 2);
function ieo_ignore_function($headers, $email_id, $order) {
$list = 'admin@example.com,cs@example.com';
$user_email = (method_exists( $order, 'get_billing_email' ))? $order->get_billing_email(): $order->billing_email;
$email_class = wc()->mailer();
if($email_id == 'customer_completed_order'){
if(stripos($list, $user_email)!==false){
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
}
}
}
但WP继续发送电子邮件。我尝试在WooCommerce文档和来源(GitHub)和Stackoverflow中搜索,但仍然无法解决。
在此示例中,"客户完成的订单"通知为特定客户电子邮件地址禁用:
// Disable "Customer completed order" for specifics emails
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'completed_email_recipient_customization', 10, 2 );
function completed_email_recipient_customization( $recipient, $order ) {
// Disable "Customer completed order
if( is_a('WC_Order', $order) && in_array($order->get_billing_email(), array('jack@mail.com','emma@mail.com') ) ){
$recipient = '';
}
return $recipient;
}
代码在您的活动子主题(活动主题)的function.php文件中。测试并起作用。
注意:滤镜需要始终返回过滤的主函数参数
也可以从用户IDS flue:
完成// Disable "Customer completed order" for specifics User IDs
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'completed_email_recipient_customization', 10, 2 );
function completed_email_recipient_customization( $recipient, $order ) {
// Disable "Customer completed order
if( is_a('WC_Order', $order) && in_array($order->get_customer_id(), array(25,87) ) ){
$recipient = '';
}
return $recipient;
}
代码在您的活动子主题(活动主题)的function.php文件中。测试并起作用。
类似:根据WooCommerce中的付款方式停止特定的客户电子邮件通知
在上面的答案工作时,这似乎是更直截了当的解决方案:
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'completed_email_recipient_customization', 10, 2 );
function completed_email_recipient_customization( $recipient, $order ) {
if( in_array($recipient, ['some@email2block.com', 'another@email2block.com'] ) ) {
$recipient = '';
}
return $recipient;
}