【问题标题】:Customizing Woocommerce New Order email notification based on shipping method [closed]根据运输方式自定义 Woocommerce 新订单电子邮件通知 [关闭]
【发布时间】:2018-02-15 09:43:40
【问题描述】:

如何编辑 admin-new-order.php WooCommerce 模板以根据运输方式有条件地发送一些自定义客户详细信息?

例如(用于新订单电子邮件通知)

  • 如果订单发货方式是flat rate,我想在客户详细信息中添加一些自定义字段信息。
  • 如果订单发货方式不是flat rate,我不希望显示自定义字段信息。

或者也许在 function.php 中有一些 sn-p 用于此?

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案1】:

    您可以使用任何挂钩中的自定义函数(调整挂钩优先级)

    • woocommerce_email_order_details
    • woocommerce_email_order_meta
    • woocommerce_email_customer_details

    这是一个挂钩代码的示例(而不是覆盖模板):

    add_action ('woocommerce_email_customer_details', 'custom_email_customer_details', 15, 4);
    function custom_email_customer_details( $order, $sent_to_admin, $plain_text, $email ){
    
        // Only for "New Order" email notification
        if ( 'new_order' != $email->id ) return;
    
        // Only "Flat Rate" Shipping Method
        if ( $order->has_shipping_method('flat_rate') ){
            $order_id = $order->get_id(); // The Order ID
    
            // Test output
            echo "<p>Message: The Order ID is $order_id</p>";
            echo '<p>Custom field: '. get_post_meta( $order_id, '_recorded_sales', true ) .'</p>';
        }
    }
    

    这里的钩子优先级是 15,所以它在客户详细信息之后。

    代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。

    此代码已经过测试并且可以工作。

    【讨论】:

    • 谢谢!如果我想有条件地删除帐单地址或送货地址详细信息或两者(屏幕截图 - prntscr.com/gioday),我应该使用什么钩子和数组?
    猜你喜欢
    • 2019-07-18
    • 2018-07-20
    • 1970-01-01
    • 2018-04-23
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    相关资源
    最近更新 更多