Are you using the Flatsome theme for your WooCommerce website and want to display product reviews in a shortcode?
With this tutorial, you’ll learn how to easily add a custom PHP snippet to your Flatsome theme and create a shortcode to showcase the reviews of the current product. By following these step-by-step instructions, you’ll be able to enhance your product pages and provide valuable social proof to your customers. Let’s get started!

- Access your WordPress admin dashboard.
- Then, Go to “Appearance” -> “Editor”.
- In the right-hand sidebar, locate and click on “Theme Functions (functions.php)”.
- Scroll down to the bottom of the “Theme Functions” file.
- Add the following PHP snippet at the end of the file:
// Return a review shortcode of a Woocommerce product
add_shortcode( 'product_reviews', 'display_product_reviews_shortcode' );
function display_product_reviews_shortcode( $atts ) {
global $post;
if ( empty( $atts ) ) return '';
$product_id = $post->ID;
$comments = get_comments( 'post_id=' . $product_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, '40' );
$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> - <time class="woocommerce-review__published-date" datetime="' . get_comment_date( 'c', $comment ) . '">' . get_comment_date( '', $comment ) . '</time></p>';
$html .= '<div class="description">';
$html .= $comment->comment_content;
$html .= '</div></div>';
$html .= '</li>';
}
$html .= '</ol></div></div>';
return $html;
}
- Click the “Update File” button to save the changes.
- Now, you can add the
[product_reviews id=""]
shortcode to any page or post where you want to display the product reviews. Edit the page or post where you want to add the shortcode. - In the editor, place your cursor at the desired location to insert the shortcode.
- Enter
[product_reviews id=""]
at that location. - Update or publish the page or post.
The provided PHP snippet adds a shortcode that will display the product reviews specific to the current product being viewed. The shortcode can be added to any page or post content using the [product_reviews id=""]
shortcode.
Please note that it’s important to always make a backup of your theme files before making any changes.
Latest Articles
Mega Menu & Custom Dropdown with UX Builder
PHP Snippet: Woocommerce Reviews as Shortcode
Best WooCommerce Themes for Your Online Shop in 2023
Remove Additional Information Tab @ Single Product