WC_REST_Taxes_V1_Controller::create_item()
Create a single tax.
Method of the class: WC_REST_Taxes_V1_Controller{}
Hooks from the method
Return
WP_Error|WP_REST_Response
.
Usage
$WC_REST_Taxes_V1_Controller = new WC_REST_Taxes_V1_Controller(); $WC_REST_Taxes_V1_Controller->create_item( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
WC_REST_Taxes_V1_Controller::create_item() WC REST Taxes V1 Controller::create item code WC 9.8.2
public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { return new WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); } $tax = $this->create_or_update_tax( $request ); $this->update_additional_fields_for_object( $tax, $request ); /** * Fires after a tax is created or updated via the REST API. * * @param stdClass $tax Data used to create the tax. * @param WP_REST_Request $request Request object. * @param boolean $creating True when creating tax, false when updating tax. */ do_action( 'woocommerce_rest_insert_tax', $tax, $request, true ); $request->set_param( 'context', 'edit' ); $response = $this->prepare_item_for_response( $tax, $request ); $response = rest_ensure_response( $response ); $response->set_status( 201 ); $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ) ); return $response; }