根据 Woocommerce 中的付款方式停止特定客户的电子邮件通知

Stop specific customer email notification based on payment methods in Woocommerce(根据 Woocommerce 中的付款方式停止特定客户的电子邮件通知)
本文介绍了根据 Woocommerce 中的付款方式停止特定客户的电子邮件通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 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 中的付款方式停止特定客户的电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)