在 Woocommerce 中使用动态数据自定义电子邮件主题 [英] Customizing email subject with dynamic data in Woocommerce

查看:70
本文介绍了在 Woocommerce 中使用动态数据自定义电子邮件主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非重复 在 Woocommerce 的订单电子邮件通知中显示含增值税和不含增值税的订单总额.

如何自定义电子邮件的主题(不是正文.我知道如何编辑正文中的变量,但相同的变量在主题出于某种原因).

How can I customize the subject of the E-mail, (not the body. I know how to edit the variables in the body, but the same variables don't work in the subject for some reason).

所以我正在尝试更改 WooCommerce 订单电子邮件通知的主题.

So I am trying to change the subject of WooCommerce order email notifications.

主题可通过 WooCommerce -> Settings -> E-mails -> New Order -> Manage... 自定义,根据 WooCommerce 文档,有诸如 {order_date} 之类的变量{customer_name} 等...可用于获取动态订单数据.

The subject is customizable via WooCommerce -> Settings -> E-mails -> New Order -> Manage… and according to WooCommerce documentation, there are variables such as {order_date}, {customer_name}, etc... that can be use to get dynamic order data.

我的问题是我想在主题中显示订单号"和订单总数":

My problem is that I would like to show the "order number" and the "order total" in the subject:

  • 如果我使用以下格式:Order {order_number} - {order_date} - {dollars_spent_order}
  • 我应该得到:订单编号 123456 - 2018 年 7 月 6 日 - {dollars_spent_order}

但它不起作用.使用单花括号或双花括号没有区别.

But it doesn't work. Using single or double curly-braces makes no difference.

如何将订单总额(包括税费、运费等)添加到电子邮件主题行?

How can I add the order total (including tax, shipping, etc) to the E-mail subject line?

我想得到以下结果:

订单编号 123456 - 2018 年 7 月 6 日 - 1,234.56 美元

Order # 123456 - July 6, 2018 - $ 1,234.56

我用谷歌搜索了这个,但没有找到任何代码片段告诉我如何做到这一点.

I Googled this, but didn't find any code snippets that show me how to do this.

还有一个WooCommerce Follow-Ups"扩展,它增加了更多的变量,但它是 99.00 美元,我不需要所有这些,只需要订单总数.在某处必须有一个代码片段......

There's also a "WooCommerce Follow-Ups" extension that adds more variables, but it's $ 99.00 and I don't need all those, just the order total. There's GOT to be a code snippet somewhere...

推荐答案

要自定义例如新订单"电子邮件主题(发送给管理员),您将使用以下挂钩函数:

To customize for example the "New Order"email subject (sent to the admin), you will use the following hooked function:

add_filter( 'woocommerce_email_subject_new_order', 'custom_email_subject', 20, 2 );
function custom_email_subject( $formated_subject, $order ){
    return sprintf( __('Order # %d - %s - %s', 'woocommerce'), 
        $order->get_id(), // Order ID
        $order->get_date_modified()->date_i18n('F j, Y'), // Formatted date modified
        wc_price($order->get_total()) // Order Total
    );
}

代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.

Code goes in function.php file of the active child theme (or active theme). Tested and works.

现在要自定义其他电子邮件通知(暂停、处理、完成或发票),您可以使用任何此过滤器挂钩:

Now to customize others email notifications (on hold, processing, completed or invoice), you can use any of this filter hooks:

  • woocommerce_email_subject_customer_on_hold_order
  • woocommerce_email_subject_customer_processing_order
  • woocommerce_email_subject_customer_completed_order
  • woocommerce_email_subject_customer_invoice
  • woocommerce_email_subject_customer_note
  • woocommerce_email_subject_low_stock
  • woocommerce_email_subject_no_stock
  • woocommerce_email_subject_backorder
  • woocommerce_email_subject_customer_new_account

补充:

如果要删除所有html以保留没有html标签的格式化价格,可以替换:

If you want to remove all html to keep the formatted price without html tags, you can replace:

wc_price($order->get_total())

by (感谢 A K):

html_entity_decode( strip_tags( wc_price( $order->get_total() ) ) );

这篇关于在 Woocommerce 中使用动态数据自定义电子邮件主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆