JS value to PHP variable to change div background color with PHP If else statement


I have the below div where i use a PHP if else to change the background color of the div based on the $tteg value which is equal to a JS value called {{ reviewsOverall }} , i don’t know if i did equal them correctly but it seems to work, the problem i am facing is the color of the background is always red, i am not sure if the below code is correct, please help.

What i want to do is IF {{ reviewsOverall }} value is below 7 div background-color to be red, else to be green, i want to mention that {{ reviewsOverall }} value starts from 0 till 10 and when its for example 5 its without decimals but if its 3.1 or others its with one decimal after the point. I am adding the below code in WordPress Plugin editor, thanks in advance for your help, much appreciated.

class="rwp-users-score <?php if ( $is_UR ) echo 'rwp-ur' ?>"
<?php $tteg = "{{ reviewsOverall }}"; ?>
 <?php if ($tteg < 7): ?>

style='background-color: red;'

<?php elseif ($tteg >= 7): ?>

style='background-color: green;'

<?php else: ?>

style='background-color: black;'

<?php endif ?> >
WordPressGeek 2 years 2020-12-30T16:10:25-05:00 0 Answers 3 views 0

Leave an answer