Have a look to this answer thread, where you'll see that you can use WC_Product
methods like:
get_average_rating()
get_rating_counts()
…
Here is a complete example:
1) Get the products required related data (customizable):
$products_data = []; // Initializing
$products = wc_get_products( ['limit' => -1] ); // Get all WC_Product objects
// Loop through products -- Preparing data to be displayed
foreach ( $products as $product ) {
$product_id = $product->get_id();
// 1. Product data as product name …
$products_data[$product_id]['name'] = $product->get_name();
// 2. Average rating and rating count
$products_data[$product_id]['rating'] = (float) $product->get_average_rating();
$products_data[$product_id]['count'] = (int) $product->get_rating_count();
// 3. Reviews -- Loop though product reviews
foreach( get_approved_comments( $product_id ) as $review ) {
if( $review->comment_type === 'review' ) {
$products_data[$product_id]['reviews'][] = (object) [
'author' => $review->comment_author,
'email' => $review->comment_author_email,
'date' => strtotime($review->comment_date),
'content' => $review->comment_content,
];
}
}
}
2) Customizable display in a table:
echo '<table class="products-reviews-ratings"><tr>
<th>'.__("ID").'</th>
<th>'.__("Name").'</th>
<th>'.__("Rating").'</th>
<th>'.__("count").'</th>
<th style="text-align:center">'.__("Reviews (author, date and content)").'</th>
</tr>';
foreach ($products_data as $product_id => $data){
echo '<tr>
<td>'.$product_id.'</td>
<td>'.$data['name'].'</td>
<td>'.$data['rating'].'</td>
<td>'.$data['count'].'</td>
<td style="text-align:center">';
if( isset($data['reviews']) && $data['reviews'] > 0 ) {
echo '<table>';
// Loop through reviews
foreach ($data['reviews'] as $review ){
echo '<tr>
<td><a href="mailto:'.$review->email.'">'.$review->author.'</a></td>
<td>'.date( 'Y-m-d', $review->date ).'</td>
<td>'.$review->content.'</td>
</tr>';
}
echo '</table>';
} else {
_e('No reviews yet');
}
echo '</td></tr>';
}
echo '</table>';
You will get something like: