Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 订单状态从挂起更改为取消时发送电子邮件通知_Php_Wordpress_Woocommerce_Orders_Email Notifications - Fatal编程技术网

Php 订单状态从挂起更改为取消时发送电子邮件通知

Php 订单状态从挂起更改为取消时发送电子邮件通知,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,在以前版本的Woocommerce中,当订单从挂起状态更改为取消状态时,会自动发送电子邮件通知(在我的情况下,这发生在管理员的库存部分中设置的分配时间之后) 在WooCommerce 3.0.8中,他们删除了此自动化并标记为修复程序: 拉动请求在这里: 我希望恢复此功能,但显然,将此行复制/粘贴回Woocommerce核心文件不是一个好主意,因为当平台更新时,它将被覆盖 我知道最好的方法是创建一个函数,并通过functions.php钩住取消订单操作,但看了之后,我有点不知道如何做。以下是被

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

在WooCommerce 3.0.8中,他们删除了此自动化并标记为修复程序:

拉动请求在这里:

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

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

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

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

好的新功能:使用带有自定义函数挂钩的操作挂钩,最终解决您的问题:

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版本4.8.0中运行至今。谢谢