Merge pull request #20024 from woocommerce/update/20022

Context for getting shipping methods for shipping zone.
This commit is contained in:
Claudiu Lodromanean 2018-05-09 10:10:27 -07:00 committed by GitHub
commit 2dc1e042c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -279,7 +279,7 @@ class WC_Settings_Shipping extends WC_Settings_Page {
wp_localize_script(
'wc-shipping-zones', 'shippingZonesLocalizeScript', array(
'zones' => WC_Shipping_Zones::get_zones(),
'zones' => WC_Shipping_Zones::get_zones( 'json' ),
'default_zone' => array(
'zone_id' => 0,
'zone_name' => '',

View File

@ -2504,7 +2504,7 @@ class WC_AJAX {
wp_send_json_success(
array(
'zones' => WC_Shipping_Zones::get_zones(),
'zones' => WC_Shipping_Zones::get_zones( 'json' ),
)
);
}

View File

@ -20,19 +20,20 @@ class WC_Shipping_Zones {
* Get shipping zones from the database.
*
* @since 2.6.0
* @param string $context Getting shipping methods for what context. Valid values, admin, json.
* @return array Array of arrays.
*/
public static function get_zones() {
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();
$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, 'json' );
$zones[ $zone->get_id() ]['shipping_methods'] = $zone->get_shipping_methods( false, $context );
}
return $zones;