WC_REST_Product_Reviews_V1_Controller::update_item()
Update a single product review.
Метод класса: WC_REST_Product_Reviews_V1_Controller{}
Хуки из метода
Возвращает
WP_Error|WP_REST_Response
.
Использование
$WC_REST_Product_Reviews_V1_Controller = new WC_REST_Product_Reviews_V1_Controller(); $WC_REST_Product_Reviews_V1_Controller->update_item( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код WC_REST_Product_Reviews_V1_Controller::update_item() WC REST Product Reviews V1 Controller::update item WC 9.2.3
public function update_item( $request ) { $product_review_id = (int) $request['id']; $product_id = (int) $request['product_id']; $review = $this->get_review( $product_review_id, $product_id ); if ( is_wp_error( $review ) ) { return $review; } $prepared_review = $this->prepare_item_for_database( $request ); $updated = wp_update_comment( $prepared_review ); if ( 0 === $updated ) { return new WP_Error( 'rest_product_review_failed_edit', __( 'Updating product review failed.', 'woocommerce' ), array( 'status' => 500 ) ); } if ( ! empty( $request['rating'] ) ) { update_comment_meta( $product_review_id, 'rating', $request['rating'] ); } $product_review = get_comment( $product_review_id ); $this->update_additional_fields_for_object( $product_review, $request ); /** * Fires after a single item is created or updated via the REST API. * * @param WP_Comment $comment Inserted object. * @param WP_REST_Request $request Request object. * @param boolean $creating True when creating item, false when updating. */ do_action( "woocommerce_rest_insert_product_review", $product_review, $request, true ); $request->set_param( 'context', 'edit' ); $response = $this->prepare_item_for_response( $product_review, $request ); return rest_ensure_response( $response ); }