WC_REST_Shipping_Zones_V2_Controller::create_item()
Create a single Shipping Zone.
Метод класса: WC_REST_Shipping_Zones_V2_Controller{}
Хуков нет.
Возвращает
WP_REST_Request|WP_Error
.
Использование
$WC_REST_Shipping_Zones_V2_Controller = new WC_REST_Shipping_Zones_V2_Controller(); $WC_REST_Shipping_Zones_V2_Controller->create_item( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код WC_REST_Shipping_Zones_V2_Controller::create_item() WC REST Shipping Zones V2 Controller::create item WC 9.3.3
public function create_item( $request ) { $zone = new WC_Shipping_Zone( null ); if ( ! is_null( $request->get_param( 'name' ) ) ) { $zone->set_zone_name( $request->get_param( 'name' ) ); } if ( ! is_null( $request->get_param( 'order' ) ) ) { $zone->set_zone_order( $request->get_param( 'order' ) ); } $zone->save(); if ( $zone->get_id() !== 0 ) { $request->set_param( 'id', $zone->get_id() ); $response = $this->get_item( $request ); $response->set_status( 201 ); $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id() ) ) ); return $response; } else { return new WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( "Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce' ), array( 'status' => 500 ) ); } }