WC_REST_Product_Reviews_V2_Controller::prepare_item_for_response()publicWC 1.0

Prepare a single product review output for response.

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

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

Возвращает

WP_REST_Response. $response Response data.

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

$WC_REST_Product_Reviews_V2_Controller = new WC_REST_Product_Reviews_V2_Controller();
$WC_REST_Product_Reviews_V2_Controller->prepare_item_for_response( $review, $request );
$review(WP_Comment) (обязательный)
Product review object.
$request(WP_REST_Request) (обязательный)
Request object.

Код WC_REST_Product_Reviews_V2_Controller::prepare_item_for_response() WC 9.3.3

public function prepare_item_for_response( $review, $request ) {
	$data = array(
		'id'               => (int) $review->comment_ID,
		'date_created'     => wc_rest_prepare_date_response( $review->comment_date ),
		'date_created_gmt' => wc_rest_prepare_date_response( $review->comment_date_gmt ),
		'review'           => $review->comment_content,
		'rating'           => (int) get_comment_meta( $review->comment_ID, 'rating', true ),
		'name'             => $review->comment_author,
		'email'            => $review->comment_author_email,
		'verified'         => wc_review_is_from_verified_owner( $review->comment_ID ),
	);

	$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
	$data    = $this->add_additional_fields_to_object( $data, $request );
	$data    = $this->filter_response_by_context( $data, $context );

	// Wrap the data in a response object.
	$response = rest_ensure_response( $data );

	$response->add_links( $this->prepare_links( $review, $request ) );

	/**
	 * Filter product reviews object returned from the REST API.
	 *
	 * @param WP_REST_Response $response The response object.
	 * @param WP_Comment       $review   Product review object used to create response.
	 * @param WP_REST_Request  $request  Request object.
	 */
	return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request );
}