WC_REST_Product_Reviews_V1_Controller::get_reviewprotectedWC 9.2.0

Fetch a single product review from the database.

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

Хуков нет.

Возвращает

\WP_Comment.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_review( $id, $product_id );
$id(int) (обязательный)
Review ID.
$product_id(int) (обязательный)
Product ID.

Список изменений

С версии 9.2.0 Введена.

Код WC_REST_Product_Reviews_V1_Controller::get_review() WC 10.4.3

protected function get_review( int $id, int $product_id ) {
	if ( 0 >= $product_id || 'product' !== get_post_type( $product_id ) ) {
		return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	$review = 0 <= $id ? get_comment( $id ) : null;
	if ( empty( $review ) || empty( $review->comment_ID ) || 'review' !== get_comment_type( $id ) || empty( $review->comment_post_ID ) || (int) $review->comment_post_ID !== $product_id ) {
		return new WP_Error( 'woocommerce_rest_product_review_invalid_id', __( 'Invalid product review ID.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	return $review;
}