WC_REST_Shipping_Zone_Methods_V2_Controller::update_item()publicWC 1.0

Update A Single Shipping Zone Method.

Метод класса: WC_REST_Shipping_Zone_Methods_V2_Controller{}

Хуков нет.

Возвращает

WP_REST_Response|WP_Error.

Использование

$WC_REST_Shipping_Zone_Methods_V2_Controller = new WC_REST_Shipping_Zone_Methods_V2_Controller();
$WC_REST_Shipping_Zone_Methods_V2_Controller->update_item( $request );
$request(WP_REST_Request) (обязательный)
Request data.

Код WC_REST_Shipping_Zone_Methods_V2_Controller::update_item() WC 8.7.0

public function update_item( $request ) {
	$zone = $this->get_zone( $request['zone_id'] );
	if ( is_wp_error( $zone ) ) {
		return $zone;
	}

	$instance_id = (int) $request['instance_id'];
	$methods     = $zone->get_shipping_methods();
	$method      = false;

	foreach ( $methods as $method_obj ) {
		if ( $instance_id === $method_obj->instance_id ) {
			$method = $method_obj;
			break;
		}
	}

	if ( false === $method ) {
		return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	$method = $this->update_fields( $instance_id, $method, $request );
	if ( is_wp_error( $method ) ) {
		return $method;
	}

	$data = $this->prepare_item_for_response( $method, $request );
	return rest_ensure_response( $data );
}