WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] How to check if a product page is in a specific category ? (3 posts)

  1. lebucheron
    Member
    Posted 1 year ago #

    Hi

    I'm looking to do a specific thing :
    Check on a product page if the product is in a specific category.

    I'm lost in all the arrays I can get.

    Thanks

    http://wordpress.org/extend/plugins/woocommerce/

  2. bheadrick
    Member
    Posted 1 year ago #

    $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;
  3. lebucheron
    Member
    Posted 1 year ago #

    Thanks, it worked like a charm

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic