elisafern – are you trying to just do the single product page, or the categories also?
Regardless, I had no trouble getting twoelevenjay’s code to work, but I ended up finding something that worked for me even better. I was trying to get my footer.php widgets to change between widget sidebars depending on which WooCommerce category you were in. It turns out, the code I found works both for WooCommerce pages and regular WordPress pages. This works the same for the single product page, the categories the product is in, etc – it’s all shared.
My WooCommerce categories were ‘children’, ‘young-people’, and ‘adults’, and I also had static WP pages with those same slugs.
<?php
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
// if in WooCommerce children category, children WP page, or a descendant of the children WP page
if ( in_array( 'children', $categories ) || is_page('children') || '29' == $post->post_parent ) {
// put code you want for this condition here
echo 'This should output only for Children!';
get_sidebar('footerchildren');
} elseif ( in_array( 'adults', $categories ) || is_page('adults') || '33' == $post->post_parent ) {
echo 'This should output only for Adults!';
get_sidebar('footeradults');
} elseif ( in_array( 'young-people', $categories ) || is_page('young-people') || '31' == $post->post_parent ) {
echo 'This should output only for Young People!';
get_sidebar('footeryoungpeople');
} else {
get_sidebar('footer');
}
?>
In the code above, you’d replace my echoes and get_sidebars with the code for content single.
As for twoelevenjay’s code, it worked fine for me as he posted though w/ instructions, I also noticed the missing bracket.