在自定义WooCommerce thankyou模板中输出订单号

时间:2017-07-18 06:51:40

标签: php wordpress templates woocommerce orders

制作自定义的感谢页面模板,如果我回显$ order = new WC_Order($ post_id),我想显示订单号;它返回值0或空字符串:但固定链接的订单ID奇怪是什么导致这个?

<strong><?php echo $order = new WC_Order($post_id); echo $order->get_order_number(); ?></strong>

整个代码如下:

<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>

<ul class="order_details">
<li class="order">
    <?php _e( 'Order number:', 'woocommerce' ); ?>
    <strong><?php echo $order = new WC_Order($post_id); echo $order->get_order_number(); ?></strong>
</li>

</ul>

1 个答案:

答案 0 :(得分:1)

您与WooCommerce checkout/thankyou.php模板相关的问题是:

  • 首先,您不能将 echo $order = new WC_Order($post_id); 一起使用,因为它是对象,但不是字符串。
  • 其次,感谢模板中已存在 $order 对象,因此您无需再次获取该对象。您可以在第一个代码行中看到:
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>

所以你的代码很简单:

<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>

<ul class="order_details">

    <li class="order">
        <?php _e( 'Order number:', 'woocommerce' ); ?>
        <strong><?php echo $order->get_order_number(); ?></strong>
    </li>

</ul>

这应该有用......