I want to get woocommerce reviews by product id and display it in a template

Kishan Shiyaliya picture Kishan Shiyaliya · Oct 15, 2013 · Viewed 40.2k times · Source

I want to fetch woocommerce product reviews by product id or anything else and want to display it in a template created by me.

Answer

user3113437 picture user3113437 · Dec 18, 2013

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:

<?php
    $args = array ('post_type' => 'product');
    $comments = get_comments( $args );
    wp_list_comments( array( 'callback' => 'woocommerce_comments' ), $comments);
?>

If you want to get the comment by product ID then you need to change that $args:

$args = array ('post_id' => 123); 

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