WC_Shipping_Zones::get_zones()public staticWC 2.6.0

Get shipping zones from the database.

Метод класса: WC_Shipping_Zones{}

Хуков нет.

Возвращает

Массив. Array of arrays.

Использование

$result = WC_Shipping_Zones::get_zones( $context );
$context(строка)
Getting shipping methods for what context. Valid values, admin, json.
По умолчанию: 'admin'

Список изменений

С версии 2.6.0 Введена.

Код WC_Shipping_Zones::get_zones() WC 8.7.0

public static function get_zones( $context = 'admin' ) {
	$data_store = WC_Data_Store::load( 'shipping-zone' );
	$raw_zones  = $data_store->get_zones();
	$zones      = array();

	foreach ( $raw_zones as $raw_zone ) {
		$zone                                = new WC_Shipping_Zone( $raw_zone );
		$zones[ $zone->get_id() ]            = $zone->get_data();
		$zones[ $zone->get_id() ]['zone_id'] = $zone->get_id();
		$zones[ $zone->get_id() ]['formatted_zone_location'] = $zone->get_formatted_location();
		$zones[ $zone->get_id() ]['shipping_methods']        = $zone->get_shipping_methods( false, $context );
	}

	return $zones;
}