1.) At the end of the “functions.php” file, add this block of code:

function prod_cat_terms_append_body( $classes ) {
    $prod_cat_terms = get_the_terms(getPostIDFromURL(), 'product_cat');

    if ( $prod_cat_terms && ! is_wp_error( $prod_cat_terms ) ){ 
        foreach ( $prod_cat_terms as $term ) {
            $classes[] = strtolower($term->slug);
    return $classes;

add_filter( 'body_class', 'prod_cat_terms_append_body', 0 );

Basically, the above code just adds the category name(s) of the current single product you are viewing into the “body” tag’s class.

For example, you are currently viewing the “Orange” product which has a “Classic Range” category. The above code function will add “classic-range” to the class of the body tag.

2.) Now that we have a “class” that we can select using CSS , we can now use the following CSS code to change the Product Title’s color when that Product is in a category Classic Range>

.classic-range .product_title {
     color: #FF3333;

Note from the code above that we reference the ”.classic-range” selector. Also note that if you have spacing in your Category title, it will be replaced by ”-”. Thus, “classic-range”.

“Soups of the world” category would be like this and so on:

.soups-of-the-world .product_title {
     color: #FF3333;
VN:F [1.9.22_1171]
Rating: 3.0/5 (1 vote cast)
Using WooCommerce, Can I Change The Color Of The Title Or Product Title Based On What Category You Are In?, 3.0 out of 5 based on 1 rating