ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2024.

WooCommerce product loop

<?php

  if ( woocommerce_product_loop() ) {
      do_action( 'woocommerce_before_shop_loop' );
      woocommerce_product_loop_start();
      if ( wc_get_loop_prop( 'total' ) ) {
          $i = 1;
          while ( have_posts() ) {
              the_post();
              do_action( 'woocommerce_shop_loop' );
              wc_get_template_part( 'content', 'product' );
              if(8 === $i){
                ?>
                <div class="cart-upsell hide-on-desktop clear">
                  <h3 class="centered">You May Also Like...</h3>
                    <?php echo do_shortcode('[products limit="2" columns="2" orderby="rand" order="DESC"]')?>
                </div>
                <?php
              }
              $i++;
          }
      }
      woocommerce_product_loop_end();
      do_action( 'woocommerce_after_shop_loop' );
  } else {
      do_action( 'woocommerce_no_products_found' );
  }
  do_action( 'woocommerce_after_main_content' );

?>