根据订单记录触发Woocommerce外发电子邮件

时间:2019-03-20 14:39:00

标签: php wordpress woocommerce orders woocommerce-rest-api

是否可以基于WooCommerce中添加的订单注释触发外发电子邮件?

我们已经与库存控制系统(Mintsoft)集成在一起,该系统基本上是通过订单记录(均通过REST API链接起来)向我们发送跟踪ID的

由于订单对象包含了您可能想要的几乎所有内容,因此我设法根据里面的文本插入注释的内容-但是,在通常的“已完成”邮件发出时,它超出了范围,这意味着不可能进行模板更改。

我的想法是根据状态禁用自动电子邮件,然后尝试自己尝试发送电子邮件,这有什么用吗?

1 个答案:

答案 0 :(得分:0)

如果您查看WC_Order add_order_note() method code,将在其中看到两个可用的钩子,并且可以使用第一个方便的钩子。

在下面的代码中,您具有所有参数数据,订单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