Automattic\WooCommerce\Internal\RestApi\Routes\V4\ShippingZones

ShippingZoneService::get_sorted_shipping_zonespublicWC 1.0

Get all shipping zones sorted by order.

Method of the class: ShippingZoneService{}

No Hooks.

Returns

Array. Array of shipping zones sorted by zone_order.

Usage

$ShippingZoneService = new ShippingZoneService();
$ShippingZoneService->get_sorted_shipping_zones();

ShippingZoneService::get_sorted_shipping_zones() code WC 10.4.3

public function get_sorted_shipping_zones() {
	$zones             = WC_Shipping_Zones::get_zones();
	$rest_of_the_world = WC_Shipping_Zones::get_zone_by( 'zone_id', 0 );

	$rest_data                            = $rest_of_the_world->get_data();
	$rest_data['zone_id']                 = $rest_of_the_world->get_id();
	$rest_data['formatted_zone_location'] = array();
	$rest_data['shipping_methods']        = $rest_of_the_world->get_shipping_methods( false, 'admin' );
	$zones[0]                             = $rest_data;

	uasort(
		$zones,
		function ( $a, $b ) {
			return $a['zone_order'] <=> $b['zone_order'];
		}
	);

	return $zones;
}