Your line of code will return an array, so you need to step through it and get the name for each zone:
$zones = WC_Shipping_Zones::get_zones();
// test $zones is an array
foreach ( $zones as $zone ) {
echo $zone['zone_name'];
}
Sorry, not tested.
I have tried your code, it works perfectly, but I noticed my assumption was wrong.
get_zones has all possible zones, not only the selected one (by selected I mean that when the customer enters his adress, it selects the zone automatically (tested, works)).
How can I get just the selected Zone?
Get the order, then get the method_id for that order. The zone id is part of the method_id, the other part being “flat-rate” or whatever.
Hey lorro,
thank you for your help.
I did it like this:
$shipping_items = $order->get_items( 'shipping' );
foreach($shipping_items as $rsd){
$order_shipping_method_id = $rsd['method_id'] ;
}
And then later:
if(strpos($order_shipping_method_id, "flat_rate:1")!==false){
//do something
}
Thank you.
-
This reply was modified 9 years, 4 months ago by
rasidrsd.
Hey lorro,
thank you for your help.
I did it like this:
$shipping_items = $order->get_items( 'shipping' );
foreach($shipping_items as $rsd){
$order_shipping_method_id = $rsd['method_id'] ;
}
And then later:
if(strpos($order_shipping_method_id, "flat_rate:1")!==false){
//do something
}
Thank you.