根据订单备注触发 Woocommerce 外发电子邮件 [英] Trigger Woocommerce outgoing email based on an order note

查看:128
本文介绍了根据订单备注触发 Woocommerce 外发电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据 WooCommerce 中添加的订单备注触发外发电子邮件?

Is it possible to trigger an outgoing email based on an added order note within WooCommerce?

我们已与库存控制系统 (Mintsoft) 集成,该系统基本上通过订单备注(全部通过 REST API 链接)将跟踪 ID 发回给我们

We've integrated with a stock control system (Mintsoft) who basically send us back the tracking ID via order notes (all linked up via the REST API)

我已经根据里面的文本成功地连接到了笔记的内容,因为订单对象几乎包含了你想要的一切——但是在通常的已完成"邮件发出时,它超出了范围,这意味着模板更改是不可能的.

I've managed to hook into the content of the note based on the text inside, as the order object contains pretty much everything you could want - however it's out of scope at the point the usual "completed" mail goes out, meaning a template change is out of the question.

我的想法是禁用基于状态的自动电子邮件并尝试我自己的,是否有一个钩子?

My idea was to disable the automatic email based on status and attempt my own, is there a hook for this?

推荐答案

如果您查看 WC_Order add_order_note() 方法代码,你会在里面看到两个可用的钩子,你可以使用第一个方便.

If you have a look to the WC_Order add_order_note() method code, you will see inside it two available hooks, and you can use the first convenient one.

在下面的代码中,您拥有所有参数数据、订单 ID、WC_Order 对象以及发送电子邮件通知的方式:

In the code below, you have all arguments data, the order Id, the WC_Order Object and the way to send an email notification:

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 文件中.经测试,应该可以.

Code goes on function.php file of your active child theme (or active theme). Tested, it should work.

相关:添加店铺Woocommerce 管理员订单备注的管理员用户名

这篇关于根据订单备注触发 Woocommerce 外发电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆