I want to fetch woocommerce product reviews by product id or anything else and want to display it in a template created by me.
Leave a Reply
You must be logged in to post a comment.
I want to fetch woocommerce product reviews by product id or anything else and want to display it in a template created by me.
You must be logged in to post a comment.
Woocommerce made a reviews out of regular wordpress comments.
The simple way is to get a comments of ‘post_type’ => ‘product’, that will get raw comment data. In order to display proper woocommerce review out of that you need to apply a callback function witch is ‘callback’ => ‘woocommerce_comments’.
The whole thing is:
If you want to get the comment by product ID then you need to change that $args:
To customize it more check out that references:
http://codex.wordpress.org/Function_Reference/wp_list_comments
http://codex.wordpress.org/get_comments
The ‘callback’ => ‘woocommerce_comments’ function uses a template located in plugins/woocomerce/templates/single-product/review.php
To display comments (reviews) simply use:
echo comments_template();
on the product page.
For more details visit here
Yes Sir, I’ve tried my level best to displays the reviews at the bottom of its default tabs, but I can’t do it for many days and finally I find your method to display the particular Product’s reviews. It working great. Awesome Sir Awesome.
But one thing more to display the product’s reviews dynamically on single-product.php
// Get the Id of product dynamically and print them (reviews) by ids.
Just Paste this code in your single-product.php file see the result. It will show as you want.
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.
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.
In
woocommerce/templates/single-product/tabs/tabs.php
If you run a
print_r()
on$tabs
after it has been declared you’ll see that a portion of the output is the following:This means that the callback is the function:
comments_template()
.Since this function doesn’t accept a
$post_id
parameter, the would need to be called within the loop.However, the function does accept a parameter of the template file to use, so to answer the OP’s direct question of how to use a custom template file – you can use the function like so:
This ^ was taken directly from the codex
Might be a little late for you Kishan since you posted a a while ago, but perhaps it will help someone else.
We just developed a free plugin to display woocommerce reviews by product id with shortcode. It also inserts Schema of the product.
Check it out, it’s free: https://shopitpress.com/plugins/sip-reviews-shortcode-woocommerce/
I tried a lot to get any built-in function for this but i didn’t. Then i wrote my own query. It might help you:
I take a week to find and had found a easy way to do it.
If you want bring review product to a page just using WP_Query and put
echo comments_template()
insideor if you want a custom template review you can using template from wp-content/plugins/woocommerce/templates/single-product-reviews.php and put inside WP_Query
Example in my case, I want bring review from product id 33051 to home page