【问题标题】:Add order number to a string in WooCommerce email body template将订单号添加到 WooCommerce 电子邮件正文模板中的字符串
【发布时间】:2020-10-19 09:40:06
【问题描述】:

我正在尝试更改保留电子邮件以在简介中包含订单号。

我添加了“$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>

【问题讨论】:

    标签: php wordpress woocommerce orders email-templates


    【解决方案1】:

    您需要连接字符串中的订单号……您可以更好地使用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>
    

    【讨论】:

      【解决方案2】:

      这是因为它现在被视为字符串的一部分,它缺少连接运算符('.')

      更多信息: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, 双重答案,同时发布

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-02
        • 1970-01-01
        • 2022-01-10
        • 1970-01-01
        • 2015-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多