woocommerce从区域ID获得运费

时间:2017-01-07 05:44:17

标签: wordpress woocommerce woocommerce-rest-api

我正在使用API​​的woocommerce添加订单。我已经使用wc_create_order()函数添加了订单。在那里,我还添加了送货地址,账单地址和产品详细信息。但问题是我想根据运输区域添加分段成本。

这是截图:

enter image description here

但是我找到了一个名为WC_Shipping_Zones::get_zones().

的函数的类

但它返回未安排的(非托管)数组。  我有州代码然后我想从州代码中获得运费。

但是,我找到了 zone_id 。  我已经尝试使用WC_Shipping_Zones::get_zone_by('zone_id',$zone_id),WC_Shipping_Zones::get_zone($zone_id);

但无论如何,任何一个函数都不会返回 成本

1 个答案:

答案 0 :(得分:1)

以下是获取区域费用的代码。我希望它有所帮助。

全球$ post,$ woocommerce;

$delivery_zones = WC_Shipping_Zones::get_zones();
foreach ((array) $delivery_zones as $key => $the_zone ) {
  echo $the_zone['zone_name'];
  echo "<br/>";
  foreach ($the_zone['shipping_methods'] as $value) {
    echo $value->cost;
  }
  echo "<br/>";
}
相关问题