WordPress at Your Fingertips
function is not described

WC_REST_Product_Reviews_V1_Controller::update_item() public WC 1.0

Update a single product review.

{} It's a method of the class: WC_REST_Product_Reviews_V1_Controller{}

Return

WP_Error|WP_REST_Response.

Usage

$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) (required)
Full details about the request.

Code of WC_REST_Product_Reviews_V1_Controller::update_item() WC 5.9.0

public function update_item( $request ) {
	$product_review_id = (int) $request['id'];
	$product_id        = (int) $request['product_id'];

	if ( 'product' !== get_post_type( $product_id ) ) {
		return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	$review = get_comment( $product_review_id );

	if ( empty( $product_review_id ) || empty( $review ) || intval( $review->comment_post_ID ) !== $product_id ) {
		return new WP_Error( 'woocommerce_rest_product_review_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	$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 );
}