From a826b363d8b41a062caf5b1569df018307b4bd7a Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 22 May 2017 15:18:55 +0100 Subject: [PATCH 1/3] Prevent zone 0 locations being changed --- .../api/class-wc-rest-shipping-zone-locations-controller.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/api/class-wc-rest-shipping-zone-locations-controller.php b/includes/api/class-wc-rest-shipping-zone-locations-controller.php index 07c965456d0..71c867bc670 100644 --- a/includes/api/class-wc-rest-shipping-zone-locations-controller.php +++ b/includes/api/class-wc-rest-shipping-zone-locations-controller.php @@ -86,6 +86,10 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_ return $zone; } + if ( 0 === $zone->get_id() ) { + return new WP_Error( "woocommerce_rest_shipping_zone_locations_invalid_zone", __( 'The "rest of the world" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); + } + $raw_locations = $request->get_json_params(); $locations = array(); From 8cba7db7cdc6696c446208c4b2cebe5b089fea3d Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 22 May 2017 15:19:04 +0100 Subject: [PATCH 2/3] Prevent zone 0 name being changed --- includes/api/class-wc-rest-shipping-zones-controller.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/api/class-wc-rest-shipping-zones-controller.php b/includes/api/class-wc-rest-shipping-zones-controller.php index fe85cfcdbaa..e77e184018c 100644 --- a/includes/api/class-wc-rest-shipping-zones-controller.php +++ b/includes/api/class-wc-rest-shipping-zones-controller.php @@ -166,6 +166,10 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle return $zone; } + if ( 0 === $zone->get_id() ) { + return new WP_Error( "woocommerce_rest_shipping_zone_invalid_zone", __( 'The "rest of the world" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); + } + $zone_changed = false; if ( ! is_null( $request->get_param( 'name' ) ) ) { From b1bf3278a795ae0860972db4b72f0cf58f769cf0 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 22 May 2017 15:19:15 +0100 Subject: [PATCH 3/3] Prevent zone 0 having locations set in CRUD --- includes/class-wc-shipping-zone.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-shipping-zone.php b/includes/class-wc-shipping-zone.php index bcc406770e1..2154e61fdc4 100644 --- a/includes/class-wc-shipping-zone.php +++ b/includes/class-wc-shipping-zone.php @@ -229,7 +229,9 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone { * @param array */ public function set_zone_locations( $locations ) { - $this->set_prop( 'zone_locations', $locations ); + if ( 0 !== $this->get_id() ) { + $this->set_prop( 'zone_locations', $locations ); + } } /* @@ -332,7 +334,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone { * @param string $type state or postcode */ public function add_location( $code, $type ) { - if ( $this->is_valid_location_type( $type ) ) { + if ( 0 !== $this->get_id() && $this->is_valid_location_type( $type ) ) { if ( 'postcode' === $type ) { $code = trim( strtoupper( str_replace( chr( 226 ) . chr( 128 ) . chr( 166 ), '...', $code ) ) ); // No normalization - postcodes are matched against both normal and formatted versions to support wildcards. }