I have a nice sitemap page which dynamically lists all posts, all pages, and most importantly, all Woocommerce Products.
I once searched on the Internet on getting a list of all woocommerce products on a page but found nothing, some guys say we can use Shortcodes included with WooCommerce, but there is none that could match the goal – list all products through sitemap template file – sitemap.php or archive.php
After digging through some boring docs, I came across some code snippets that work.
woocommerce get list of all products via template file
Insert the core snippet below into sitemap template file at proper position:
<h2>Products:</h2> <ul> <?php $loop = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => 1000, 'orderby' => 'title', 'order' => 'ASC' ) ); ?> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <li><?php the_title( '<a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a>' ); ?></li> <?php endwhile; ?> </ul>
To understand it thoroughly, you need to study