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(); 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' ) ) ) { 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. }