WordPress at Your Fingertips
function is not described

WC_API_Products::get_product_reviews() public WC 2.1

Get the reviews for a product

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

Return

Array|WP_Error.

Usage

$WC_API_Products = new WC_API_Products();
$WC_API_Products->get_product_reviews( $id, $fields );
$id(int) (required)
the product ID to get reviews for
$fields(string)
fields to include in response
Default: null

Changelog

Since 2.1 Introduced.

Code of WC_API_Products::get_product_reviews() WC 5.7.1

public function get_product_reviews( $id, $fields = null ) {

	$id = $this->validate_request( $id, 'product', 'read' );

	if ( is_wp_error( $id ) ) {
		return $id;
	}

	$args = array(
		'post_id' => $id,
		'approve' => 'approve',
	);

	$comments = get_comments( $args );

	$reviews = array();

	foreach ( $comments as $comment ) {

		$reviews[] = array(
			'id'             => $comment->comment_ID,
			'created_at'     => $this->server->format_datetime( $comment->comment_date_gmt ),
			'review'         => $comment->comment_content,
			'rating'         => get_comment_meta( $comment->comment_ID, 'rating', true ),
			'reviewer_name'  => $comment->comment_author,
			'reviewer_email' => $comment->comment_author_email,
			'verified'       => wc_review_is_from_verified_owner( $comment->comment_ID ),
		);
	}

	return array( 'product_reviews' => apply_filters( 'woocommerce_api_product_reviews_response', $reviews, $id, $fields, $comments, $this->server ) );
}