Too explain more, I have a shopping website where many of the products are not rated but I would like to show some default rating like 3 stars or 5 stars for each product which is not rated. The purpose is to show ratings for each products in any possible way. Is it possible? Please let me know how can I do it in the best easiest way.
Asked
Active
Viewed 68 times
-3
-
3[How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Jomoos Mar 07 '17 at 07:34
1 Answers
0
With some search, Here is what I found :
PHP Method WC_Product::set_average_rating, woocommerce Code Examples
So, I suppose you could do something like this :
foreach ($products as $product) {
$count = $product->get_rating_count();
if (!$count) {
$average = 0.65;
}
$product->set_average_rating($average);
$data_store = $product->get_data_store();
$data_store->update_average_rating($product);
}
/!\ not tested.
Hope it helps.

JazZ
- 4,469
- 2
- 20
- 40
-
Where should I use this, I mean in which file? Do I need to copy this to functions.php? – user3644999 Mar 08 '17 at 06:07