简体   繁体   English

在管理新订单电子邮件模板中添加应用的优惠券代码 - WooCommerce

[英]Add Applied Coupon Code in Admin New Order Email Template - WooCommerce

Let me clear my question:让我澄清一下我的问题:

  • I have downloaded & activated WooCommerce Plugin for E-Commerce Functionality.我已经下载并激活了用于电子商务功能的 WooCommerce 插件。
  • I want to add "Applied coupon code" in Admin New Order Email Template using my custom plugin.我想使用我的自定义插件在管理新订单电子邮件模板中添加“应用的优惠券代码”。

Now:现在:

  1. Can you tell me that exact Hook or Function which is actually setting up that New Order Email Template so that i will override it?你能告诉我实际设置新订单电子邮件模板的确切钩子或函数,以便我覆盖它吗?
  2. Can you tell me how to call applied coupon code, so that i will display this in email template?你能告诉我如何调用应用的优惠券代码,以便我将其显示在电子邮件模板中吗?

It would be great, if you help me please.如果你能帮助我,那就太好了。

This can be done using a custom function hooked in woocommerce_email_order_details action hook (for example) that will display in admin emails notifications the used coupons in the order:这可以使用挂钩在 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>';
    }
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。

Tested and works...经过测试和工作...

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将应用优惠券描述添加到 WooCommerce 管理员 Email 通知 - Add Applied Coupon Description to WooCommerce Admin Email notifications 将优惠券代码名称添加到 Woocommerce 查看订单详细信息和电子邮件通知 - Add the Coupon Code names to Woocommerce View Order details and email notifications 在WooCommerce中应用特定优惠券代码时发送电子邮件通知 - Send an email notification when a specific coupon code is applied in WooCommerce 当在 WooCommerce 中应用特定优惠券代码时,向客户发送 email 通知 - Send an email notification to customer when a specific coupon code is applied in WooCommerce 在Woocommerce中将订单交易ID添加到管理员新订单电子邮件通知中 - Add orders transaction id to admin new order email notification in Woocommerce 在优惠券设置中添加字段并在 Woocommerce 管理订单列表中显示值 - Add a field to coupon settings and display the value on Woocommerce admin order list Woocommerce 新订单电子邮件模板 - Woocommerce New Order Email Template 在 WooCommerce 管理员优惠券列表中添加一个带有作者姓名的新列 - Add a new column with author name to WooCommerce admin coupon list 在 WooCommerce 订单上使用优惠券代码时发送 email 通知 - Send an email notification when a coupon code is used on a WooCommerce Order 如何在 WooCommerce 中的已完成订单 email 模板中添加新帐户信息 - How to add new account info on order completed email template in WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM