Automattic\WooCommerce\RestApi\Routes\V4\ShippingZones
ShippingZoneSchema::get_formatted_zone_locations
Get array of location names for display.
Метод класса: ShippingZoneSchema{}
Хуков нет.
Возвращает
Массив.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_formatted_zone_locations( $zone, $view ): array;
- $zone(WC_Shipping_Zone) (обязательный)
- Shipping zone object.
- $view(строка)
- The view for which the API is requested ('summary' or 'detailed').
По умолчанию: 'summary'
Код ShippingZoneSchema::get_formatted_zone_locations() ShippingZoneSchema::get formatted zone locations WC 10.3.6
protected function get_formatted_zone_locations( WC_Shipping_Zone $zone, string $view = 'summary' ): array {
if ( 0 === $zone->get_id() ) {
return array( __( 'All regions not covered above', 'woocommerce' ) );
}
$locations = $zone->get_zone_locations();
if ( 'summary' === $view ) {
$location_names = array();
foreach ( $locations as $location ) {
$location_names[] = $this->get_location_name( $location );
}
return $location_names;
} else {
// For detailed view, add name property to each location object.
$detailed_locations = array();
foreach ( $locations as $location ) {
$location_copy = clone $location;
$location_copy->name = $this->get_location_name( $location );
$detailed_locations[] = $location_copy;
}
return $detailed_locations;
}
}