I am working with WooCommerce project for my client and i need to show products listing loop with pagination. I was searching for how to write custom products listing loop in WooCommerce and after a bit research, i found a way. Here i am sharing a code with you.
Custom WooCommerce Product Listing Loop
WooCommerce is using “product” as custom post type so you can write WP_Query with custom post type parameter as “product”. Below is the code.
<?php // Write custom query as per your needs $args = array( 'post_type' => 'product' ); $products = new WP_Query( $args ); while ( $products->have_posts() ) : $products->the_post(); ?> <a href="<?php echo get_permalink( $products->post->ID ) ?>"> <?php the_title(); ?> </a> <?php endwhile; wp_reset_query(); // Reset WP Query ?>
Isn’t it easy to list all products as per your needs and in specific area of your web page ? Looking for How to Write Custom Products Listing Loop in WooCommerce, WooCommerce Products listing loop custom query, custom query to get products in WooCommerce than this is perfect solution for you.