WooCommerce Get Store Rating
Today, we will be talking about how to get store ratings by products in WooCommerce or wordpress. This tutorial will guide you to get your store rating based on the product rating. Once you get the ratings on your products in store, the total average rating of these products achieved will be the average rating of your store.
Below is an example:
$products = wc_get_products( array( 'status' => 'publish', 'limit' => -1 ) );
if($products){
foreach($products as $product){
if($product->get_review_count())
$total = $total+ $product->get_review_count();
$j = $j+1;
$totalRating = $totalRating + $product->get_average_rating();
}
}
echo 'Average Rating: '.round($totalRating/$j,1);
echo 'Total Review: '.$total;
if($products){
foreach($products as $product){
if($product->get_review_count())
$total = $total+ $product->get_review_count();
$j = $j+1;
$totalRating = $totalRating + $product->get_average_rating();
}
}
echo 'Average Rating: '.round($totalRating/$j,1);
echo 'Total Review: '.$total;
Here is an available free extension WooCommerce Store Rating extension.