Add custom body class from woocommerce product category page

Can somebody come up with something clever on how to add a custom body class or a class to a specific wrapper div from the woocommerce product category page?

I have thought of using the category description, but it dosent look like a nice solution. I want it just to generate two classes, either “light” or “dark”.

Read More

Anyone??

Kind regards,
Ricahrd

Related posts

2 comments

  1. PHP Snippet: Add WooCommerce Product Category as Body CSS Class
    You can place PHP snippets at the bottom of your child theme functions.php file (before “?>” if you have it). CSS, on the other hand, goes in your child theme style.css file.

    add_filter( 'body_class', 'bbloomer_wc_product_cats_css_body_class' );
    
        function bbloomer_wc_product_cats_css_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;
              }
            }
          }
          return $classes;
        }
    

Comments are closed.