Automattic\WooCommerce\Blocks\Utils

CartCheckoutUtils::get_shipping_zones()public staticWC 1.0

Retrieves formatted shipping zones from WooCommerce.

Method of the class: CartCheckoutUtils{}

No Hooks.

Return

Array. An array of formatted shipping zones.

Usage

$result = CartCheckoutUtils::get_shipping_zones();

CartCheckoutUtils::get_shipping_zones() code WC 9.0.1

public static function get_shipping_zones() {
	$shipping_zones             = \WC_Shipping_Zones::get_zones();
	$formatted_shipping_zones   = array_reduce(
		$shipping_zones,
		function( $acc, $zone ) {
			$acc[] = [
				'id'          => $zone['id'],
				'title'       => $zone['zone_name'],
				'description' => $zone['formatted_zone_location'],
			];
			return $acc;
		},
		[]
	);
	$formatted_shipping_zones[] = [
		'id'          => 0,
		'title'       => __( 'International', 'woocommerce' ),
		'description' => __( 'Locations outside all other zones', 'woocommerce' ),
	];
	return $formatted_shipping_zones;
}