admin管理员组

文章数量:1122832

I'm using Woocommerce and I'm trying to get the total for each star rating using the post id (just like in the image below). Each rating is stored on my database as a number from 1 - 5 I just don't know how to go about retrieving the total count for each rating.

Any help will be greatly appreciated.

I'm using Woocommerce and I'm trying to get the total for each star rating using the post id (just like in the image below). Each rating is stored on my database as a number from 1 - 5 I just don't know how to go about retrieving the total count for each rating.

Any help will be greatly appreciated.

Share Improve this question asked Nov 20, 2017 at 17:45 ed_mdked_mdk 232 silver badges7 bronze badges 2
  • this is the standard Woocommerce rating ? or something else ? – Temani Afif Commented Nov 20, 2017 at 18:31
  • I'm using standard woocommerce rating, however the image is from a plugin. – ed_mdk Commented Nov 20, 2017 at 19:03
Add a comment  | 

1 Answer 1

Reset to default 4

You can use the function get_rating_count() by specifying on each call the value needed. For example :

global $product;

$rating_1 = $product->get_rating_count(1);
$rating_2 = $product->get_rating_count(2);
$rating_3 = $product->get_rating_count(3);
$rating_4 = $product->get_rating_count(4);
$rating_5 = $product->get_rating_count(5);

You can read more about the function

本文标签: woocommerce offtopicHow to get total count for each star rating