WC_REST_Shipping_Zone_Locations_V2_Controller::update_items()
Update all Shipping Zone Locations.
Method of the class: WC_REST_Shipping_Zone_Locations_V2_Controller{}
No Hooks.
Return
WP_REST_Response|WP_Error
.
Usage
$WC_REST_Shipping_Zone_Locations_V2_Controller = new WC_REST_Shipping_Zone_Locations_V2_Controller(); $WC_REST_Shipping_Zone_Locations_V2_Controller->update_items( $request );
- $request(WP_REST_Request) (required)
- Request data.
WC_REST_Shipping_Zone_Locations_V2_Controller::update_items() WC REST Shipping Zone Locations V2 Controller::update items code WC 7.7.0
public function update_items( $request ) { $zone = $this->get_zone( (int) $request['id'] ); if ( is_wp_error( $zone ) ) { return $zone; } if ( 0 === $zone->get_id() ) { return new WP_Error( 'woocommerce_rest_shipping_zone_locations_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); } $raw_locations = $request->get_json_params(); $locations = array(); foreach ( (array) $raw_locations as $raw_location ) { if ( empty( $raw_location['code'] ) ) { continue; } $type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country'; if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) { continue; } $locations[] = array( 'code' => sanitize_text_field( $raw_location['code'] ), 'type' => sanitize_text_field( $type ), ); } $zone->set_locations( $locations ); $zone->save(); return $this->get_items( $request ); }