我正在使用 WooCommerce 在 Wordpress 上开发电子商务网站。我想在订单确认页面(即付款后)检索并显示客户在结账时选择的“运输方式”(即交付或收集等)。
我正在尝试使用 get_post_meta($post_id, $key, $single)
来做到这一点功能。我无法这样做,因为我不知道 $key 值。
我尝试了以下代码(在 php 标签内):
echo get_post_meta( $order_id, 'shipping_method', true );
但它返回一个空白值(页面上没有显示)。我假设我使用的不正确
$key
.我愿意接受使用其他(更简单的)方法来实现这一目标的建议。
最佳答案
从 WooCommerce 3 开始,如果您想获得运输格式的方法标题,最好使用 WC_Order
方法 get_shipping_method()
喜欢:
// Get the WC_Order object from the Order ID
$order = wc_get_order( $order_id );
// Output the shipping method(s) formatted method title(s)
echo $order->get_shipping_method();
有关其他运输项目的详细信息,请参阅以下主题:
关于php - 如何在 WooCommerce 中检索订单的运输方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57444694/