【问题标题】:Which hook to add custom data In New Order Admin Woocommerce email在新订单管理员 Woocommerce 电子邮件中添加自定义数据的挂钩
【发布时间】:2018-04-29 15:17:49
【问题描述】:

在 WooCommerce 中,我可以如何以及在何处为新订单电子邮件通知应用一些代码,我应该在哪里获得应用的优惠券代码显示。

在新订单电子邮件通知的模板中,我有@hooked WC_Emails::order_details(),它显示了订单详细信息表……

WC_Email::order_details() 也是我正在寻找的用于更新新订单邮件中的优惠券代码给管理员的确切钩子?

我很松散,任何帮助将不胜感激......

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce coupon


    【解决方案1】:

    您正在搜索的钩子是 woocommerce_email_order_details 可以这样使用的动作钩子:

    add_action( 'woocommerce_email_order_details', 'action_email_order_details', 10, 4 );
        function action_email_order_details( $order, $sent_to_admin, $plain_text, $email ) {
         if( $sent_to_admin ): // For admin emails notification
    
         // Your code goes HERE
    
         endif;
    }
    

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


    在您的函数中,您可以使用来自钩子的 4 个参数中的任何一个,例如 $orderWC_Order 对象。

    您可以使用WC_Abstract_Order 方法get_used_coupons() 为您提供订单中使用的一系列优惠券代码,例如:

    // Get the array of coupons codes
    $coupon_codes = $order->get_used_coupons();
    
    // Convert and display the array in a coma separated string:
    echo 'Coupon codes: ' . implode( ', ', $coupon_codes );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2020-03-11
      • 2019-05-21
      相关资源
      最近更新 更多