Change background of div class using product category IDs
-
I want to change div class background color by fetching product category IDs. I wrote code using if else condition, but it is using last else condition even category IDs 49 or 50 is true.
<?php
if ( $category_ID == 49 ) {
$color = ‘#FF0000’;
} else if ( $category_ID == 50 ) {
$color = ‘#0C2D4E’;
} else {
$color = ‘#00FF21’;
}
?><div class=”color” style=”background-color: <?php echo $color; ?>;”>
<?php the_title( ‘<h1 class=”product_title entry-title”>’, ‘</h1>’ ); ?>
</div>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Change background of div class using product category IDs’ is closed to new replies.