是否可以根据 WooCommerce 中添加的订单备注触发外发电子邮件?
我们已经与库存控制系统 (Mintsoft) 集成,该系统基本上通过订单备注向我们发回跟踪 ID(全部通过 REST API 链接)
我已经成功地根据内部文本 Hook 了注释的内容,因为订单对象几乎包含了您可能想要的所有内容 - 然而,在通常的“已完成”邮件发出时,它超出了范围,这意味着模板更改是不可能的。
我的想法是禁用基于状态的自动电子邮件并尝试我自己的,有一个钩子(Hook)吗?
最佳答案
如果您查看WC_Order
add_order_note()
method code ,您将在其中看到两个可用的 Hook ,您可以使用第一个方便的 Hook 。
在下面的代码中,您拥有所有参数数据、订单 ID、WC_Order 对象以及发送电子邮件通知的方式:
add_filter( 'woocommerce_new_order_note_data', 'filter_woocommerce_new_order_note_data', 10, 2 );
function filter_woocommerce_new_order_note_data( $args, $args2 ) {
if( ! $args2['is_customer_note'] ){
// Get an instance of the WC_Order Object
$order = wc_get_order( $args2['order_id'] );
// Getting all WC_emails objects
$mailer = WC()->mailer()->get_emails();
// Send the "Completed" notification
$mailer['WC_Email_Customer_Completed_Order']->trigger( $args2['order_id'] );
}
return $args;
}
代码位于事件子主题(或事件主题)的 function.php 文件中。经过测试,应该可以工作。
相关:Add the Shop Manager username to Woocommerce Admin Order notes
关于php - 根据订单备注触发 Woocommerce 传出电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55263397/