+923465009310 info@designinggeeks.com
How to Style Individual Woocommerce Product Category

How to Style Individual Woocommerce Product Category

You’ll need to add a function to your theme’s functions.php file. This adds the product category to the product page’s body tag.


// add taxonomy term to body_class
function woo_custom_taxonomy_in_body_class( $classes ){
if( is_singular( 'product' ) )
{
$custom_terms = get_the_terms(0, 'product_cat');
if ($custom_terms) {
foreach ($custom_terms as $custom_term) {
$classes[] = 'product_cat_' . $custom_term->slug;
}

The CSS class to target would be product_cat_SLUG, where SLUG is replaced with the categories slug.

The slug can be found by viewing the categories under Products > Categories, they are lower case with spaces replaced with dashes.