WC_Shipping_Zones::get_zones( string $context = 'admin' )

Get shipping zones from the database.


Description Description


Parameters Parameters

$context

(Optional) Getting shipping methods for what context. Valid values, admin, json.

Default value: 'admin'


Top ↑

Return Return

(array) Array of arrays.


Top ↑

Source Source

File: includes/class-wc-shipping-zones.php

	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;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.