The summary rating is automatically calculated by the average rating of all reviews. While you can filter the rating number in the summary, it won’t add up with the summary percentages.
However, to filter the summary rating, you could do something like this:
add_filter('site-reviews/summary/value/rating', function ($value) {
return $value >= 4.5 ? 5 : $value;
});
Thanks a lot for your fast answer!
Your code will change my 4.9 rating value to 5, but unfortunately the stars are not affected by this.
I’d actually want to have 5 full stars displayed but still the rating of 4.9
Thanks to your (hook) example I managed to solve it like this:
add_filter('site-reviews/summary/value/stars', function ($value) {
preg_match("/<strong>(\d*(?:\.\d+)?)<\/strong>/", $value, $matches);
if (isset($matches[1])) {
$v = floatval($matches[1]);
$value = ($v >= 4.5) ? glsr_star_rating(5) : $value;
}
return $value;
});
It’s kinda hacky but it seems to do the job as long as the template for the stars won’t be changed.
Thank you.
In that case, you could also do this:
add_filter('site-reviews/defaults/star-rating', function (array $values) {
if ($values['rating'] >= 4.5) {
$values['rating'] = 5;
}
return $values;
});
This will work for the summary since only the summary rating has fractional ratings.
-
This reply was modified 5 years, 1 month ago by
Gemini Labs.
Thank you, that seems perfect, but somehow it has no effect at all at a page with the summary on it.
Also a glsr_debug inside this hook’s function does not trigger.
I implemented it right there where my solution above works.
I have tested it and it works for me.


Ok, I’ll have another look!
This can be marked as solved though. π
Thanks a lot for your great help!