Score x 2 (from 1 to 10)
-
Is there a way to change the scores from 1-5 to 1-10? To add a formula in one of the files to do the scores times 2? Hope you can help me with that!
-
Technically yes, however it’s not recommended for the following reasons.
- Changing the maximum rating number is not officially supported. So if you experience problems after changing to 10 stars you may have to figure it out yourself if the problem is related to the rating.
- Changing to 10 stars when you have existing 1-5 star reviews will mess up your rating counts. You would need to apply the change before you have any reviews.
- Once you have set it to 10 stars, you will not easily be able to revert to 5 stars.
- The addons have not been tested with a 10-star rating system, so if you are using them you may experience problems that I may not be able to help you solve.
If you would like to go ahead with this change in spite of the points listed above, you may do so like this:
/** * Changes the maximum rating to 10 stars * @return int */ add_filter('site-reviews/const/MAX_RATING', function () { return 10; }); /** * Changes the rating validation to allow 10 stars * @param array $rules * @return array */ add_filter('site-reviews/validation/rules', function ($rules) { if (array_key_exists('rating', $rules)) { $rules['rating'] = 'required|between:0,10'; } return $rules; }); /** * Changes the summary bars labels for each of the 10 stars * @param array $args * @param string $shortcode * @return array */ add_filter('site-reviews/shortcode/args', function ($args, $shortcode) { if ('site_reviews_summary' === $shortcode) { $args['labels'] = '10 stars,9 stars,8 stars,7 stars,6 stars,5 stars,4 stars,3 stars,2 stars,1 star'; } return $args; }, 10, 2);
Thanks for your response! This seems tricky and more complex. What I actually mean is not changing the system from 5 to 10 stars, but only doubling the total score (mean score of all reviews) that is shown in the site reviews summary.
- Install the Code Snippets plugin
- Add a new snippet
- Enter as the title: Change Site Reviews to 10 Stars
- Paste in the code snippet provided above
- Click “Save Changes”
- Click “Activate”
Is there a way to only change (multiply by 2) the overall rating that is shown in reviews summary?
Yes, but I don’t think it would make much sense to do so. If you only change the summary rating number (by doubling it), the rating won’t match the reviews on your page, and the schema (if you are using it) will be invalid.
- Reviews use 5-stars
- Review Form uses 5 stars
- Summary shows 5 stars
- There are only 5 percentage bars in the Summary
- The schema uses 5 stars
If you are still convinced that you want to do it, here is a code snippet:
add_filter('site-reviews/summary/value/rating', function ($value) { if (is_numeric($value)) { return (int) $value * 2; } return $value; });
- This reply was modified 1 year, 7 months ago by Gemini Labs.
We are used to rate things from 1 to 10 in our country. So I would really like the shown rating summary score to be doubled.
Thanks a lot for helping me out with providing the code. It doesn’t seem to work however. Don’t know why. I already tried to multiply the returned value outside the if-statement too. Then I get a score of 8. Does it only take the first number? Would like to double the decimal too. So 4,9 would become 9,8 and not 8.
Can you please give it another shot?
Ah, try this:
add_filter('site-reviews/summary/value/rating', function ($value) { if (is_numeric($value)) { return (float) $value * 2; } return $value; });
Could it be the case that the decimals are not recognized because the separator is a comma? With string_replace I can turn it into a dot, which works fine (showing the right score), but can’t get it back in comma after the multiplication.
Probably. Site Reviews displays the summary rating in the number format of your WordPress locale.
Try this:
add_filter('site-reviews/summary/value/rating', function ($value) { $rating = str_replace(',', '.', (string) $value); $rating = (float) $rating * 2; return (string) number_format_i18n($rating, 1); });
- The topic ‘Score x 2 (from 1 to 10)’ is closed to new replies.