【问题标题】:Send an email notification when order status change from pending to cancelled当订单状态从待处理变为已取消时发送电子邮件通知
【发布时间】:2018-01-25 17:01:08
【问题描述】:

在以前版本的 Woocommerce 中,当订单从待处理状态更改为已取消状态时,会自动发送电子邮件通知(在我的情况下,这发生在管理员库存部分中设置的分配时间之后)。

在 WooCommerce 3.0.8 中,他们已删除此自动化并标记为修复: https://github.com/woocommerce/woocommerce/blob/master/CHANGELOG.txt

拉取请求在这里: https://github.com/woocommerce/woocommerce/pull/15170/files

我希望恢复此功能,但显然将此行复制/粘贴回 Woocommerce 核心文件不是一个好主意,因为它会在平台更新时被覆盖。

我知道最好的方法是创建一个函数并通过functions.php 挂钩到取消的订单操作,但看了之后我有点迷失了如何做到这一点。这是被替换的行:

add_action( 'woocommerce_order_status_pending_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );

如何恢复这个旧的自动化功能?

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案1】:

    好消息:使用woocommerce_order_status_pending_to_cancelled动作钩子和自定义函数钩子,彻底解决您的问题:

    add_action('woocommerce_order_status_pending_to_cancelled', 'cancelled_send_an_email_notification', 10, 2 );
    function cancelled_send_an_email_notification( $order_id, $order ){
        // Getting all WC_emails objects
        $email_notifications = WC()->mailer()->get_emails();
    
        // Sending the email
        $email_notifications['WC_Email_Cancelled_Order']->trigger( $order_id );
    }
    

    代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。

    在 WooCommerce 3+ 中测试并完美运行(仍然适用于 4.8+ 版本)

    【讨论】:

    • 它在 woocommerce v 4.8.0 中一直有效。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2018-01-04
    • 2018-10-20
    • 2019-12-05
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多