【问题标题】:Disable WooCommerce email notification for specific Order Id禁用特定订单 ID 的 WooCommerce 电子邮件通知
【发布时间】:2018-07-04 12:46:17
【问题描述】:

我需要禁用特定订单 ID 的电子邮件通知。例如,在 woocommerce 订单 ID 2378 中,我想仅针对此订单 ID 禁用客户的所有电子邮件通知。因为我仍然遇到订单自行更改状态的问题。这对我们来说是一个持续存在的问题,不幸的是,我无法找到原因。但是,自从 9 月第一次下达以来,有一个特殊的订单一直在改变状态。

我在下面找到了一些禁用电子邮件通知的代码。但我不知道如何使用特定订单 ID 的功能。

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );

function unhook_those_pesky_emails( $email_class ) {

remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) ); // cancels automatic email of order complete status update.
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) ); // cancels automatic email of new order placed (when defined to procession status)
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); // cancels automatic email of status update to processing.
}

【问题讨论】:

  • 把你的代码放到functions.php文件里检查一下。
  • 当我输入此代码时,所有自动电子邮件通知都被禁用。
  • 您已经从文件夹结构中使用了 wordpress 主题。正确的??您在项目中激活了主题文件夹。主题文件夹中有一个functions.php 文件,其中放置了代码。希望!你明白...
  • @PriyankaModi 我知道,但是这段代码对我不起作用,这就是为什么我在这里问这个问题,当我输入这段代码时,所有电子邮件通知都不起作用。我想禁用特定订单的电子邮件通知你明白我的意思吗?
  • 不幸的是,这是不可能的……

标签: php wordpress woocommerce email-notifications


【解决方案1】:

参加聚会已经很晚了,但它可能会对某人有所帮助。

这个想法怎么样?

add_filter( 'woocommerce_email_recipient_customer_on_hold_order', 'customer_on_hold_order_for_specified_order', 10, 2 );

function customer_on_hold_order_for_specified_order( $recipient, $order ) {
    if( is_a($order, 'WC_Order') && $order->get_id() === 2378 ) {
        $recipient = '';
    }
    return $recipient;
}

对每封激活的电子邮件都执行此操作?

在应得的地方给予表扬:谢谢@LoicTheAztec

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2021-06-09
    • 2018-03-10
    • 2019-07-23
    • 2018-02-06
    相关资源
    最近更新 更多