简体   繁体   English

将订单号添加到 WooCommerce 电子邮件正文模板中的字符串

[英]Add order number to a string in WooCommerce email body template

I'm trying to change the on-hold email to include the order number in the introduction.我正在尝试更改保留电子邮件以在介绍中包含订单号。

I've added "$order->get_id()" to show the order number.我添加了“$order->get_id()”来显示订单号。 Not quite working.不太工作。 Any ideas?有任何想法吗?

<p><?php esc_html_e( 'Thanks for your order. Your order number is $order->get_id(). Below you can find the contents of your order.', 'woocommerce' ); ?></p>

This is because it is now seen as part of the string, it's missing the concatenation operator ('.')这是因为它现在被视为字符串的一部分,它缺少连接运算符('.')

More info: String Operators更多信息:字符串运算符

Use it like this instead像这样使用它

<p><?php esc_html_e( 'Thanks for your order. Your order number is ' . $order->get_id() . ' Below you can find the contents of your order.', 'woocommerce' ); ?></p>

Example:例子:

Not不是

'First part of string $myvar Second part of string';

But

'First part of string' . $myvar . 'Second part of string';


EDIT编辑

Another option: see Loic's answer , double answer, posted simultaneously另一种选择:参见Loic 的回答,双重回答,同时发布

您需要连接字符串中的订单号……您可以更好地使用printf()WC_Order方法get_order_number() ,如下所示:

<p><?php printf( esc_html__( 'Thanks for your order. Your order number is %s. Below you can find the contents of your order.', 'woocommerce' ), $order->get_order_number() ); ?></p>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM