WooCommerce: Display Product Reviews @ Custom Page (Shortcode)

WooCommerce product reviews shows by default in the “Reviews” tab in the single product page. But what if, like me, you’re using custom sales pages and need to show such reviews elsewhere – by using a shortcode?

I’ve spent some time doing this for two Business Bloomer pages, the contact page (beside the request a quote form) and the Bloomer Armada sales page (just above the pricing table), so I thought it would have been great sharing the snippet with you. Enjoy!

Here’s my custom “WooCommerce product reviews shortcode” output on a test website homepage.

PHP Snippet: WooCommerce Product Reviews Shortcode

Once the snippet below is added to your functions.php, simply use shortcode [product_reviews id="123"] anywhere you like. Please note “id” is the ID of the product for which you want to output customer reviews.

 * @snippet       WooCommerce Product Reviews Shortcode
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.9
 * @donate $9     https://businessbloomer.com/bloomer-armada/

add_shortcode( 'product_reviews', 'bbloomer_product_reviews_shortcode' );

function bbloomer_product_reviews_shortcode( $atts ) {
	if ( empty( $atts ) ) return '';

	if ( ! isset( $atts['id'] ) ) return '';
	$comments = get_comments( 'post_id=' . $atts['id'] );
	if ( ! $comments ) return '';
	$html .= '<div class="woocommerce-tabs"><div id="reviews"><ol class="commentlist">';
	foreach ( $comments as $comment ) {	
		$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
		$html .= '<li class="review">';
		$html .= get_avatar( $comment, '60' );
		$html .= '<div class="comment-text">';
		if ( $rating ) $html .= wc_get_rating_html( $rating );
		$html .= '<p class="meta"><strong class="woocommerce-review__author">';
		$html .= get_comment_author( $comment );
		$html .= '</strong></p>';
		$html .= '<div class="description">';
		$html .= $comment->comment_content;
		$html .= '</div></div>';
		$html .= '</li>';
	$html .= '</ol></div></div>';
	return $html;

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

4 thoughts on “WooCommerce: Display Product Reviews @ Custom Page (Shortcode)

  1. This is great, thanks for sharing. Is there a way to also add Leave your rating above or below the reviews similar to that in the woocommerce tab as well so someone can leave a review also?

    1. Hi Lori, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Another super helpful snippet to learn from!

    Q: What is the best way to manually populate comments into the system? We have many to use from another application that we’d like to populate throughout the site (they are not specifically product related).

    Thanks –

    1. Hi Rick, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Questions? Feedback? Support? Leave your Comment Now!

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *