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

ShippingZoneSchema::get_formatted_zone_locationsprotectedWC 1.0

Get array of location objects for API response.

Method of the class: ShippingZoneSchema{}

No Hooks.

Returns

Array. Array of location objects with code, type, and name.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_formatted_zone_locations( $zone ): array;
$zone(WC_Shipping_Zone) (required)
Shipping zone object.

ShippingZoneSchema::get_formatted_zone_locations() code WC 10.4.3

protected function get_formatted_zone_locations( WC_Shipping_Zone $zone ): array {
	if ( 0 === $zone->get_id() ) {
		return array();
	}

	$locations           = $zone->get_zone_locations();
	$formatted_locations = array();

	foreach ( $locations as $location ) {
		$formatted_locations[] = array(
			'code' => isset( $location->code ) ? $location->code : '',
			'type' => isset( $location->type ) ? $location->type : 'country',
			'name' => $this->get_location_name( $location ),
		);
	}

	return $formatted_locations;
}