Skip to content

Instantly share code, notes, and snippets.

@kanlukasz
Forked from woogists/wc-sample-products-loop.php
Created November 24, 2021 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanlukasz/4cf9bf5a357f15cb66a8c0eb5c58137c to your computer and use it in GitHub Desktop.
Save kanlukasz/4cf9bf5a357f15cb66a8c0eb5c58137c to your computer and use it in GitHub Desktop.
[Theming Snippets] Sample products loop
<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><!--/.products-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment