Rest of the world is a default zone with ID 0. it has no ‘object’ like other zones. You can still retrieve it and the methods though.
Thanks Mike. You didn’t really said how to retrieve it 😉 but I think I figure it out. For other wanting to do the same:
$zones = array();
// Rest of the World zone
$zone = new \WC_Shipping_Zone();
$zones[ $zone->get_zone_id() ] = $zone->get_data();
$zones[ $zone->get_zone_id() ]['formatted_zone_location'] = $zone->get_formatted_location();
$zones[ $zone->get_zone_id() ]['shipping_methods'] = $zone->get_shipping_methods();
// Add user configured zones
$zones = array_merge( $zones, \WC_Shipping_Zones::get_zones() );
Note: I use namespaces, therefore need to use \WC_Shipping_Zones instead of just WC_Shipping_Zones. Adap for your case.
@mike – if this is a poor way of doing it, let us know a better way.
All my shipping zones have a fixed flat rate.
I’ve been trying to create a simple shortcode function so I could display a list of accepted shipping zones along with their most reliable information such as the zone name, the country/state, the method title, the cost, as also all the zip codes for each shipping zone.
I’m able to retrieve all the shipping zones names from the array with the function bellow, but the other stuff I need to list are too deep within the array. Could anyone help me to achieve that?
The function:
function shipping_zones_shortcode() {
$delivery_zones = WC_Shipping_Zones::get_zones();
foreach ((array) $delivery_zones as $key => $the_zone ) {
echo $the_zone['zone_name'];
}
print_r($delivery_zones);
}
add_shortcode( 'shipping_zones', 'shipping_zones_shortcode', 10 );
how can I get value of Rest of the World zone ?
I have answered to that successfully on StackOverFlow:
Getting all Free Shipping Zones include the default Zone “Rest of the World”
To resume the code to use as default Zone has O as ID is:
$default_zone = new WC_Shipping_Zone(0);
$default_zone_data = $default_zone->get_data();
print_r($default_zone_data);