woocommerce get shipping cost from zone id

3.4k views Asked by At

I am working in woocommerce add order from API. I already added order by using wc_create_order() function. In that, I have added shipping address, billing address, and product details as well. But the problem is I want to add shpping cost as per shipping zone.

Here is screenshot :

enter image description here

However I found class with function called : WC_Shipping_Zones::get_zones().

But it return unarranged (unmanaged) array. I have state code and then I want to get shipping cost from state code.

However, I have found zone_id. I have already tried to use WC_Shipping_Zones::get_zone_by('zone_id',$zone_id),WC_Shipping_Zones::get_zone($zone_id);

But none of functions return cost anyhow.

1

There are 1 answers

0
Arun George On

Here is the code to get the zone cost. I hope it helps.

global $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/>";
}