WC_REST_Shipping_Zone_Methods_V2_Controller::create_item()
Create a new shipping zone method instance.
Метод класса: WC_REST_Shipping_Zone_Methods_V2_Controller{}
Хуков нет.
Возвращает
WP_REST_Request|WP_Error
.
Использование
$WC_REST_Shipping_Zone_Methods_V2_Controller = new WC_REST_Shipping_Zone_Methods_V2_Controller(); $WC_REST_Shipping_Zone_Methods_V2_Controller->create_item( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код WC_REST_Shipping_Zone_Methods_V2_Controller::create_item() WC REST Shipping Zone Methods V2 Controller::create item WC 9.3.3
public function create_item( $request ) { $method_id = $request['method_id']; $zone = $this->get_zone( $request['zone_id'] ); if ( is_wp_error( $zone ) ) { return $zone; } $instance_id = $zone->add_shipping_method( $method_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_not_created', __( 'Resource cannot be created.', 'woocommerce' ), array( 'status' => 500 ) ); } $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 ); }