WC_REST_Taxes_V1_Controller::update_item()publicWC 1.0

Update a single tax.

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

Хуки из метода

Возвращает

WP_Error|WP_REST_Response.

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

$WC_REST_Taxes_V1_Controller = new WC_REST_Taxes_V1_Controller();
$WC_REST_Taxes_V1_Controller->update_item( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код WC_REST_Taxes_V1_Controller::update_item() WC 8.7.0

public function update_item( $request ) {
	$id      = (int) $request['id'];
	$tax_obj = WC_Tax::_get_tax_rate( $id, OBJECT );

	if ( empty( $id ) || empty( $tax_obj ) ) {
		return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	$tax = $this->create_or_update_tax( $request, $tax_obj );

	$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, false );

	$request->set_param( 'context', 'edit' );
	$response = $this->prepare_item_for_response( $tax, $request );
	$response = rest_ensure_response( $response );

	return $response;
}