PHP Question

Woocommerce product stars how to show in shop page?

I want to show the number of reviews and average star ratings of a product in Shop/ Product Archive pages. Currently this is shown in single product pages. But I want it in all-products page. How can I achieve that? Please help. Thank you very much.

Answer

You can put this into your theme functions.php file:

To show the average star ratings of a product in Shop/ Product Archive pages -

add_action('woocommerce_after_shop_loop_item', 'add_star_rating' );
function add_star_rating()
{
global $woocommerce, $product;
$average = $product->get_average_rating();

echo '<div class="star-rating"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div>';
}
Comments