Skip to content

Instantly share code, notes, and snippets.

@thegdshop
Created July 29, 2012 10:52
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thegdshop/3197540 to your computer and use it in GitHub Desktop.
Save thegdshop/3197540 to your computer and use it in GitHub Desktop.
WooCommerce - Add category body class in single product view
<?php
// add taxoonomy 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;
}
}
}
return $classes;
}
add_filter( 'body_class', 'woo_custom_taxonomy_in_body_class' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment