I am trying to add a parent product category from Woocommerce as a class in wordpress' body .
Every time I go to a child category, the parent category is no longer included in the body class.
Can I edit something like below to find the parent category and add to the body tag?
Maybe a term like "product_parent_cat"? I tried this and looked for their API, but did not succeed.
function woo_custom_taxonomy_in_body_class( $classes ){ $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; } add_filter( 'body_class', 'woo_custom_taxonomy_in_body_class' );
source share