php - 如何在 WooCommerce 中检索订单的运输方式?

标签 php wordpress woocommerce orders shipping-method

我正在使用 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();

有关其他运输项目的详细信息,请参阅以下主题:
  • Get orders shipping method details in WooCommerce 3
  • Show Shipping Method data on the Order edit pages in WooCommerce
  • 关于php - 如何在 WooCommerce 中检索订单的运输方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57444694/

    相关文章:

    php - wordpress安装错误is_read

    php - 仅针对 Woocommerce 中的特定订单状态和付款方式减少库存

    php - 基于数量计算的产品类别的购物车折扣

    php - 使用 htaccess,如何限制查看目录内容,但允许服务器使用内容?

    php - 尝试在提交前获取菜单值

    javascript - 无法处理 jQuery 表单事件

    wordpress - 从哪里开始使用 Google Reader 作为 API?

    php - 如果没有促销价,如何显示 woocommerce 促销价或正常价格

    php - mysql中的ID重置

    php - MYSQLi 和 ssl 连接到数据库服务器