title: Woocommerce products from category loop
body: <p>In Woocommerce, I Need some help with this custom product loop, in my code my result is : <a href="https://i.stack.imgur.com/aPFey.png" rel="nofollow noreferrer">how it looks like</a></p>
  
  <p>The loop doesn't stop and it is looping the same products for three or four times. </p>
  
  <p>The code I am using is here :</p>
  
  <pre><code>&lt;div class="container"&gt;
      &lt;div id="default_products_page_container" class="wrap wpsc_container"&gt;
          &lt;?php
              remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
              remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
              $cat = get_query_var( 'product_cat' );
              $args = array( 'post_type' =&gt; 'product', 'posts_per_page' =&gt; 5, 'product_cat' =&gt; $cat, 'orderby' =&gt; 'rand' );
              $loop = new WP_Query( $args );
          ?&gt;
          &lt;div class="wpsc_default_product_list"&gt;
              &lt;?php
              while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); global $product; ?&gt;
              &lt;div class="col-lg-4 col-md-4 col-sm-12 col-xs-12"&gt;
                  &lt;div class="default_product_display product_view_&lt;?php echo get_permalink( $loop-&gt;post-&gt;ID ); ?&gt;group"&gt;
                      &lt;a href="&lt;?php echo get_permalink( $loop-&gt;post-&gt;ID ) ?&gt;" title="&lt;?php echo esc_attr($loop-&gt;post-&gt;post_title ? $loop-&gt;post-&gt;post_title : $loop-&gt;post-&gt;ID); ?&gt;"/&gt;
                      &lt;?php if (has_post_thumbnail( $loop-&gt;post-&gt;ID ))
                      {            
                      ?&gt;         
                      &lt;div class="product-image-thumb"&gt; 
                          &lt;img src="&lt;?php echo the_post_thumbnail_url( $loop-&gt;post-&gt;ID );?&gt;"/&gt;
                      &lt;/div&gt;
                      &lt;?php
                      } else 
                      {?&gt;
                      &lt;div class="product-image-thumb"&gt;
                          &lt;a&gt;
                              &lt;img src="&lt;?php echo woocommerce_placeholder_img_src();?&gt;"/&gt;
                          &lt;/a&gt;
                      &lt;/div&gt;
                      &lt;?php } ?&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;?php endwhile; ?&gt;
          &lt;/div&gt;
          &lt;?php wp_reset_query(); ?&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>