I want to show Woocommerce products on my custom template page How can i get product collection in that page,Please kindly give some suggestions how do i proceed to complete it
thanks
I want to show Woocommerce products on my custom template page How can i get product collection in that page,Please kindly give some suggestions how do i proceed to complete it
thanks
Share Improve this question asked Oct 9, 2017 at 6:51 Learing_CoderLearing_Coder 1191 silver badge3 bronze badges 1- What have you done? – Samuel Asor Commented Oct 9, 2017 at 6:53
2 Answers
Reset to default 2I found like this. For More : https://docs.woocommerce/document/sample-products-loop/ https://www.philowen.co/blog/show-latest-woocommerce-products-in-your-template/
<?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();
?>
Just try it. i hope is useful
You didn't provide much detail here, but you could also try to add them as a list:
<?php
$params = array('posts_per_page' => 5, 'post_type' => 'product');
$wc_query = new WP_Query($params);
?>
<ul>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) :
$wc_query->the_post(); ?>
<li>
<h3>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php the_post_thumbnail(); ?>
<?php the_excerpt(); ?>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<li>
<?php _e( 'No Products' ); ?>
</li>
<?php endif; ?>
</ul>
More details would allow us to help you more specifically.