I found and use the code (Thanks to the creator of this code!) Display total customers reviews and ratings average in WooCommerce
It displays (in my case) on the product page and on the taxonomy page the number of all reviews and rating from the entire store.
For example: I have a custom taxonomy "brand_name". I want Adidas products (taxonomy "brand_name") to display only their average rating of all products and quantity. And only if the overall rating of the goods is more than 3 stars. and for Nike (taxonomy "brand_name"), only their average rating of all products and quantity were displayed. And only if the overall rating of the goods is more than 3 stars.
Thank you very much for your help and attention to my post.
The code I use (original above link)
function get_total_reviews_count(){
return get_comments(array(
'status' => 'approve',
'post_status' => 'publish',
'post_type' => 'product',
'count' => true
));
}
function get_products_ratings(){
global $wpdb;
return $wpdb->get_results("
SELECT t.slug, tt.count
FROM {$wpdb->prefix}terms as t
JOIN {$wpdb->prefix}term_taxonomy as tt ON tt.term_id = t.term_id
WHERE t.slug LIKE 'rated-%' AND tt.taxonomy LIKE 'product_visibility'
ORDER BY t.slug
");
}
function products_count_by_rating_html(){
$star = 1;
$html = '';
foreach( get_products_ratings() as $values ){
$star_text = '<strong>'.$star.' '._n('Star', 'Stars', $star, 'woocommerce').'<strong>: ';
$html .= '<li class="'.$values->slug.'">'.$star_text.$values->count.'</li>';
$star++;
}
return '<ul class="products-rating">'.$html.'</ul>';
}
function products_rating_average_html(){
$stars = 1;
$average = 0;
$total_count = 0;
if( sizeof(get_products_ratings()) > 0 ) :
foreach( get_products_ratings() as $values ){
$average += $stars * $values->count;
$total_count += $values->count;
$stars++;
}
return '<p class="rating-average">'.round($average / $total_count, 1).' / 5 '. __('Stars average').'</p>';
else :
return '<p class="rating-average">'. __('No reviews yet', 'woocommerce').'</p>';
endif;
}
echo '<p>'.__('Total reviews','woocommerce').': '.get_total_reviews_count().'</p>';
echo products_count_by_rating_html();
echo products_rating_average_html();