【问题标题】:Trigger Woocommerce outgoing email based on an order note根据订单注释触发 Woocommerce 外发电子邮件
【发布时间】:2019-08-11 07:15:33
【问题描述】:

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

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

我已经设法根据里面的文本挂钩到便笺的内容,因为订单对象几乎包含您想要的所有内容 - 但是在通常的“已完成”邮件发出时它超出了范围,这意味着模板更改是不可能的。

我的想法是禁用基于状态的自动电子邮件并尝试我自己的,这有什么钩子吗?

【问题讨论】:

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


    【解决方案1】:

    如果您查看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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      • 2021-07-20
      • 2019-01-22
      • 1970-01-01
      • 2017-08-08
      相关资源
      最近更新 更多