> For the complete documentation index, see [llms.txt](https://madeindonesia.gitbook.io/mi-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://madeindonesia.gitbook.io/mi-guide/plugins/woocommerce/woocommerce-loop.md).

# WooCommerce Loop

A loop checks to see if more products (for a specific condition) are left to display.\
\
If there are, the product details are grabbed from the database, rendered to screen, and the process then restarts or loops around until no more products are left to display.

```
<ul class="products">
	<?php
		$args = array(
			'post_type' => 'product',
			'posts_per_page' => 12
		);
		$loop = new WP_Query( $args );
		if ( $loop->have_posts() ) {
			while ( $loop->have_posts() ) : $loop->the_post();
				wc_get_template_part( 'content', 'product' );
			endwhile;
		} else {
			echo __( 'No products found' );
		}
		wp_reset_postdata();
	?>
</ul>
```

1. The WP\_Query object to set up the database query to get product data.
2. The product search criteria are set from the $args array on lines 3-6.
3. The query looks for post types ‘product’, with page pagination set to return 12 products per page.
4. wc\_get\_template\_part() - is a woocommerce hook to get template part (for templates like the shop-loop).\
   wc\_get\_template\_part( $slug, $name );
5. Make a message  if there is no product in this case i use this message " No Products Found".&#x20;
6. wp\_reset\_postdata() After looping through a separate query, this function restores the $post global to the current post in the main query.
