WC_REST_Product_Attributes_V1_Controller::update_item()
Update a single term from a taxonomy.
Method of the class: WC_REST_Product_Attributes_V1_Controller{}
Hooks from the method
Return
WP_REST_Request|WP_Error
.
Usage
$WC_REST_Product_Attributes_V1_Controller = new WC_REST_Product_Attributes_V1_Controller(); $WC_REST_Product_Attributes_V1_Controller->update_item( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
WC_REST_Product_Attributes_V1_Controller::update_item() WC REST Product Attributes V1 Controller::update item code WC 9.4.2
public function update_item( $request ) { global $wpdb; $id = (int) $request['id']; $edited = wc_update_attribute( $id, array( 'name' => $request['name'], 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), 'type' => $request['type'], 'order_by' => $request['order_by'], 'has_archives' => $request['has_archives'], ) ); // Checks for errors. if ( is_wp_error( $edited ) ) { return new WP_Error( 'woocommerce_rest_cannot_edit', $edited->get_error_message(), array( 'status' => 400 ) ); } $attribute = $this->get_attribute( $id ); if ( is_wp_error( $attribute ) ) { return $attribute; } $this->update_additional_fields_for_object( $attribute, $request ); /** * Fires after a single product attribute is created or updated via the REST API. * * @param stdObject $attribute Inserted attribute object. * @param WP_REST_Request $request Request object. * @param boolean $creating True when creating attribute, false when updating. */ do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, false ); $request->set_param( 'context', 'edit' ); $response = $this->prepare_item_for_response( $attribute, $request ); return rest_ensure_response( $response ); }