I have a Wordpress website (a restaurant review page), and on my main page I have a snippet that returns back a number (from 1 to 100) from the post to display the grade of the restaurant.
Current situation
It looks like this:
The code that display this is this one:
<?php
if ( class_exists( "Lets_Review_API" ) ) {
$lr_api = new Lets_Review_API();
$final_score_value = $lr_api->lets_review_get_final_score_only( $post_id );
echo '<div class="show-score"><h4>' . $final_score_value . '%</h4></div>';
}
?>
The CSS snippet of this particular part looks like this:
.show-score {
padding: 0.25rem 0.35rem;
border-radius: var(--cs-category-label-border-radius);
color: var(--cs-color-category-contrast);
background-color: var(--cs-color-category);
}
What do I want
I want the background-color of this part to change based on the rating that was given. So for example, if the rating is from 1 to 40 it shows red, from 41 to 80 yellow and from 81 to 100 a green color. I've been searching on Google and here with different keywords (I'm not a native English speaker or a developer of any kind in that matter) but couldn't find the desired result or answer.
Thank you in advance for provided help.
What I did (and didn't work)
I tried adding this:
<?php
if ( class_exists( "Lets_Review_API" ) ) {
$lr_api = new Lets_Review_API();
$final_score_value = $lr_api->lets_review_get_final_score_only( $post_id );
if ($final_score_value > 1 && $final_score_value < 40) { $score_class = 'red' };
echo '<div class="show-score ' + . $score_class . +'"><h4>' . $final_score_value . '%</h4></div>';
}
?>
as I checked around to see what would work, but Wordpress won't let me save the file, as there is an unexpected "}" in this line - if ($final_score_value > 1 && $final_score_value < 40) { $score_class = 'red' };
