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

ShippingZoneSchema::get_location_nameprotectedWC 1.0

Get location name from location object.

Method of the class: ShippingZoneSchema{}

No Hooks.

Returns

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_location_name( $location );
$location(object) (required)
Location object.

ShippingZoneSchema::get_location_name() code WC 10.4.3

protected function get_location_name( $location ) {
	switch ( $location->type ) {
		case 'continent':
			$continents = WC()->countries->get_continents();
			return isset( $continents[ $location->code ] ) ? $continents[ $location->code ]['name'] : $location->code;

		case 'country':
			$countries = WC()->countries->get_countries();
			return isset( $countries[ $location->code ] ) ? $countries[ $location->code ] : $location->code;

		case 'state':
		case 'country:state':
			$parts = explode( ':', $location->code );
			if ( count( $parts ) === 2 ) {
				$states = WC()->countries->get_states( $parts[0] );
				return isset( $states[ $parts[1] ] ) ? $states[ $parts[1] ] : $location->code;
			}
			return $location->code;

		case 'postcode':
			return $location->code;

		default:
			return $location->code;
	}
}