Created
October 7, 2015 09:15
-
-
Save Langmans/7ab8a8d1687fe691cb7b to your computer and use it in GitHub Desktop.
add all woocommerce product categories to body_class
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
<?php | |
// add all woocommerce product categories to body_class | |
function product_category_body_classes( $classes ){ | |
if( is_singular( 'product' ) || is_tax( 'product_cat' ) ) { | |
foreach (get_the_terms(0, 'product_cat') as $custom_term) { | |
do { | |
$classes[] = 'product-category-' . $custom_term->slug; | |
//if( is_singular( 'product' ) ) { | |
$classes[] = 'term-' . $custom_term->term_id; | |
//} | |
// Get the parent product category: | |
$custom_term = $custom_term->parent ? get_term( $custom_term->parent, 'product_cat' ) : null; | |
//var_dump($custom_term); | |
} while ($custom_term); | |
} | |
} | |
return $classes; | |
} | |
add_filter( 'body_class', 'product_category_body_classes' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment