php 订单取消,php – 在Woocommerce中取消订单时向客户发送电子邮件

在这个隐藏在woocommerce_order_status_changed动作钩子中的自定义函数中,我定位“取消”和“失败”的订单向客户发送相应的电子邮件通知(管理员将通过WooCommerce自动通知接收它):

add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );

function send_custom_email_notifications( $order_id, $old_status, $new_status, $order ){

if ( $new_status == 'cancelled' || $new_status == 'failed' ){

$wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects instances

$customer_email = $order->get_billing_email(); // The customer email

}

if ( $new_status == 'cancelled' ) {

// change the recipient of this instance

$wc_emails['WC_Email_Cancelled_Order']->recipient = $customer_email;

// Sending the email from this instance

$wc_emails['WC_Email_Cancelled_Order']->trigger( $order_id );

}

elseif ( $new_status == 'failed' ) {

// change the recipient of this instance

$wc_emails['WC_Email_Failed_Order']->recipient = $customer_email;

// Sending the email from this instance

$wc_emails['WC_Email_Failed_Order']->trigger( $order_id );

}

}

代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中.

这应该适用于WooCommerce 3

If you need, instead of changing the email, you can add it, to existing recipients:

06001

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值