title: How to check if a woocommerce product has any category assigned to it?
body: <p>I am creating a custom plugin where related products are fetched as per the tags assigned to a product. I am facing an issue. When i run a loop it gives me a warning message. What i want to check is that if the particular product has any category assigned to it. How can i check if any category has been assigned to a woocommerce product. Please help me. Thanks in advance. </p>
  
  <p><strong>my custom code</strong> </p>
  
  <pre><code>while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); 
      global $product;
      global $post;
  
      $feat_image = wp_get_attachment_url( get_post_thumbnail_id($loop-&gt;post-&gt;ID) );
      $terms200 = get_the_terms( $loop-&gt;post-&gt;ID, 'product_cat' );
  
  
          // if(!empty($terms200) || $terms200!='' || $terms200!=null){   
      if (get_category($loop-&gt;post-&gt;ID)-&gt;category_count != 0){        
          $content.='&lt;li class="product-small  grid1 grid-normal"&gt;';
              $content.='&lt;div class="inner-wrap"&gt;';
                  $content.='&lt;a href="'.get_the_permalink($loop-&gt;post-&gt;ID).'"&gt;';
                      $content.='&lt;div class="product-image hover_fade_in_back"&gt;';
                          $content.='&lt;div class="front-image"&gt;';
                              $content.='&lt;img src="'.$feat_image.'" class="attachment-shop_catalog wp-post-image" style="width:247px !important;height:300px !important;" /&gt;';
                          $content.='&lt;/div&gt;';
                      $content.='&lt;/div&gt;';
                  $content.='&lt;/a&gt;';
                  $content .='&lt;div class="info style-grid1"&gt;';
                      $content .='&lt;div class="text-center"&gt;';
                          $count=1;
                          foreach ( @$terms200 as $term ) {
                                  if($count==1){
                                      $content.='&lt;h5 class="category"&gt;&lt;a href="'.get_site_url().'/?product_cat='.$term-&gt;slug.'" rel="tag"&gt;'.$term-&gt;name.'&lt;/a&gt;&lt;/h5&gt;';  
                                      $content.='&lt;div class="tx-div small"&gt;&lt;/div&gt;';   
                                  }
                              $count++;
                          }
                          $content .='&lt;a href="'.get_the_permalink($loop-&gt;post-&gt;ID).'"&gt;&lt;p class="name"&gt;'.$loop-&gt;post-&gt;post_title.'&lt;/p&gt;&lt;/a&gt;';
                          if ( $price_html = $product-&gt;get_price_html() ) :
                          $content .='&lt;span class="price"&gt;&lt;span class="amount"&gt;'.$price_html.'&lt;/span&gt;&lt;/span&gt;';
                          endif;
                          $content.='&lt;div class="mycustomcartbuttonbox"&gt;[add_to_cart id="'.$loop-&gt;post-&gt;ID.'"]&lt;/div&gt;';                                
                      $content .='&lt;/div&gt;';
                  $content .='&lt;/div&gt;';
              $content.='&lt;/div&gt;';
          $content.='&lt;/li&gt;';
          echo do_shortcode($content);
  
      }   
  
  endwhile;
  </code></pre>