• Resolved firebird1999

    (@firebird1999)


    Hey,
    I’m rebuilding an existing site with wordpress and this plugin.
    So, because it was like this before: When my rating is 4.5 (up to 4.9) I’m trying to show 5 full stars in the summary (instead of 4.5).
    When it’s less than 4.5 it should display as usual and everything else should also stay the same.

    Thanks for your help in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    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;
    });
    Thread Starter firebird1999

    (@firebird1999)

    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.

    Plugin Author Gemini Labs

    (@geminilabs)

    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 3 years, 7 months ago by Gemini Labs.
    Thread Starter firebird1999

    (@firebird1999)

    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.

    Plugin Author Gemini Labs

    (@geminilabs)

    I have tested it and it works for me.

    Thread Starter firebird1999

    (@firebird1999)

    Ok, I’ll have another look!
    This can be marked as solved though. ??

    Thanks a lot for your great help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Modifying star amount in summary’ is closed to new replies.