【问题标题】:Add Applied Coupon Code in Admin New Order Email Template - WooCommerce在管理员新订单电子邮件模板中添加应用的优惠券代码 - WooCommerce
【发布时间】:2017-11-16 05:22:51
【问题描述】:

让我澄清一下我的问题:

  • 我已下载并激活 WooCommerce 电子商务功能插件。
  • 我想使用我的自定义插件在管理员新订单电子邮件模板中添加“已应用的优惠券代码”。

现在:

  1. 您能告诉我实际设置新订单电子邮件模板的确切 Hook 或函数,以便我覆盖它吗?
  2. 您能告诉我如何调用已申请的优惠券代码,以便我将其显示在电子邮件模板中吗?

如果你能帮助我,那就太好了。

【问题讨论】:

    标签: php wordpress woocommerce coupon email-notifications


    【解决方案1】:

    这可以使用 woocommerce_email_order_details 操作钩子(例如)中的自定义函数来完成,该函数将在管理员电子邮件通知中显示订单中使用的优惠券:

    // The email function hooked that display the text
    add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
    function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {
    
        // Only for admins and when there at least 1 coupon in the order
        if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;
    
        foreach( $order->get_items('coupon') as $coupon ){
            $coupon_codes[] = $coupon->get_code();
        }
        // For one coupon
        if( count($coupon_codes) == 1 ){
            $coupon_code = reset($coupon_codes);
            echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';
        } 
        // For multiple coupons
        else {
            $coupon_codes = implode( ', ', $coupon_codes);
            echo '<p>'.__( 'Coupons Used: ').$coupon_codes.'<p>';
        }
    }
    

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

    经过测试并且可以工作...

    【讨论】:

      【解决方案2】:

      这是因为$coupon_codes 不是数组() 用$coupon_codes=array(); 定义它

      【讨论】:

        猜你喜欢
        • 2020-07-28
        • 1970-01-01
        • 2020-11-24
        • 1970-01-01
        • 1970-01-01
        • 2019-04-02
        • 1970-01-01
        • 1970-01-01
        • 2019-07-02
        相关资源
        最近更新 更多