当订单状态从待处理变为取消时发送电子邮件通知 [英] Send an email notification when order status change from pending to cancelled

查看:87
本文介绍了当订单状态从待处理变为取消时发送电子邮件通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In previous versions of Woocommerce, an email notification was sent automatically when an order was changed from pending status to cancelled status (In my case, this happens after an allotted time set in the inventory section of the admin).

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

In WooCommerce 3.0.8 they have removed this automation and labelled as a fix: https://github.com/woocommerce/woocommerce/blob/master/CHANGELOG.txt

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

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

I'm looking to restore this functionality, but obviously copy/pasting this line back in to the Woocommerce core files isn't a good idea as it will get overwritten when the platform updates.

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

I know the best method would to be to create a function and hook into the cancelled order action via functions.php but after having a look I'm a bit lost about how to do this. Here is the line which was replaced:

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

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

How can I restore this old automated functionality?

推荐答案

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

The good new: Using woocommerce_order_status_pending_to_cancelled action hook with a custom function hook in it, solve your problem definitively:

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+ 版本)

Tested and perfectly works in WooCommerce 3+ (still work on version 4.8+)

这篇关于当订单状态从待处理变为取消时发送电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆