Support » Plugin: WooCommerce » How to check if a product page is in a specific category ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • $targetcatslug = 'apples';
    $incat=false;
    $terms = get_the_terms( $post->ID, 'product_cat' );
    
    if ( $terms && ! is_wp_error( $terms ) ) : 
    
    	foreach ( $terms as $term ) {
    		if($term->slug==$targetcatslug) $incat = true;
    	}
    endif;

    Thanks, it worked like a charm

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to check if a product page is in a specific category ?’ is closed to new replies.