I want to fetch woocommerce product reviews by product id or anything else and want to display it in a template created by me.
I have been recently having the same struggle and I came up with this solution that allows you to output reviews from all products on a single page.
//Display all product reviews
if (!function_exists('display_all_reviews')) {
function display_all_reviews(){
$args = array(
'status' => 'approve',
'type' => 'review'
);
// The Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );
// Comment Loop
if ( $comments ) {
echo "";
foreach ( $comments as $comment ): ?>
comment_approved == '0' ) : ?>
- id="li-review-comment_ID; ?>">
comment_author_email, $size = '50' ); ?>
comment_content; ?>
";
} else {
echo "This product hasn't been rated yet.";
}
}
}
Add the above function to your functions.php file. After this you can use this function on your theme wherever you would like by calling it like this:
I also created a tutorial here https://www.majas-lapu-izstrade.lv/get-woocommerce-customer-reviews-from-all-products-display-average-and-all-ratings-in-a-histogram-without-a-plugin/ that also includes functions to output average product rating, total count of all ratings from all products and all product review histogram.