Merge pull request #20024 from woocommerce/update/20022
Context for getting shipping methods for shipping zone.
This commit is contained in:
commit
2dc1e042c9
|
@ -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' => '',
|
||||
|
|
|
@ -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' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue