【发布时间】:2021-12-13 07:46:45
【问题描述】:
WooCommerce 默认模式是在订单状态发生变化时向客户发送电子邮件。但是管理员/商店经理如何知道何时进行了这些更改?保持订单页面 24/7 全天候打开并刷新视图不是解决方案。
我已尝试以下代码,但这不适用于自定义订单状态。
add_filter('woocommerce_email_recipient_customer_processing_order', 'email_recipient_custom_notification', 10, 2);
function email_recipient_custom_notification( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
error_log("Hello: woocommerce_email_recipient_customer_processing_order : recipient = " . $recipient . "\n" );
// Set HERE your replacement recipient email(s)… (If multiple, separate them by a coma)
$recipient .= ', admin@xyz.com';
return $recipient;
}
add_filter('woocommerce_email_recipient_customer_out-to-delivery_order', 'email_out_to_delivery_notification', 10, 2);
function email_out_to_delivery_notification( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
error_log("Hello: woocommerce_email_recipient_customer_out-to-delivery_order : recipient
= " . $recipient . "\n" );
// Set HERE your replacement recipient email(s)… (If multiple, separate them by a coma)
$recipient .= ', admin@xyz.com';
return $recipient;
}
请注意,'out-to-delivery' 是我已成功添加的自定义订单状态。我可以将订单状态从“暂停-->处理-->发货-->完成”更改。
通过上述更改,网站管理员会收到“新订单”和“处理中”订单状态的通知。但他没有收到有关“交货外”或“已完成”状态更改的通知。似乎我使用的过滤器'woocommerce_email_recipient_customer_out-to-delivery_order'不起作用。
谢谢
【问题讨论】:
-
你可以试试这个钩子
woocommerce_process_shop_order_meta -
您正在使用的钩子会为现有的电子邮件通知添加收件人,这些通知无论如何都会发送。除非您已有效提供此信息,否则不会针对自定义订单状态发送电子邮件。是这样吗? “请注意,'out-to-delivery' 是我已成功添加的自定义订单状态。” - 您能否详细说明如何添加此/这些,以便您的问题包含 a Minimal, Reproducible Example
-
嗨@MainulHasan,当订单状态改变时,钩子'woocommerce_process_shop_order_meta'被调用。但我的目标是向商店管理员发送电子邮件通知。如何使用这个钩子来做到这一点?
-
@user2679476 以下答案包含您问题答案的 90% -> Add a new order status that Send an email notification in WooCommerce 4+ - 您唯一需要添加的是电子邮件也会发送给管理员,即已经适用于您的代码尝试
-
嗨@7uc1f3r,事实上我试过这个链接。但是当我添加此行时,它会给出错误(此网站出现严重错误。请检查您的网站管理员电子邮件收件箱以获取说明。):- add_action( 'woocommerce_order_status_wc-out-to-delivery', array( WC() , 'send_transactional_email' ), 10, 1 );
标签: woocommerce hook-woocommerce