Last active
April 14, 2020 19:27
-
-
Save mio31337/2bacd581fa008e125f984d841b3b8830 to your computer and use it in GitHub Desktop.
WooCommerce: Add Product Cateogry class to body on single Product page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add Product Cateogry class to body on single Product page | |
* Author: MarioMarkovic.com | |
*/ | |
add_filter( 'body_class', 'wc_product_cats_css_body_class' ); | |
function wc_product_cats_css_body_class( $classes ){ | |
if ( is_singular( 'product' ) ) { | |
$current_product = wc_get_product(); | |
$custom_terms = get_the_terms( $current_product->get_id(), 'product_cat' ); | |
if ( $custom_terms ) { | |
foreach ( $custom_terms as $custom_term ) { | |
$classes[] = 'product_cat_' . $custom_term->slug; | |
} | |
} | |
} | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment