制作自定义的感谢页面模板,如果我回显$ 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>
答案 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>
这应该有用......