问题描述
我正在尝试更改保留的电子邮件,以在简介中包含订单号。
我添加了“ $ order-> get_id()”以显示订单号。不太正常。有什么想法吗?
<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>
解决方法
这是因为它现在被视为字符串的一部分,缺少连接运算符('.')
更多信息:String Operators
改为使用它
<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>
示例:
不是
'First part of string $myvar Second part of string';
但是
'First part of string' . $myvar . 'Second part of string';
编辑
另一个选项:请参见Loic's answer, 双重答案,同时发布
,您需要将字符串中的订单号连接起来……可以更好地使用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>