最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to get woocommerce product collection in template file

programmeradmin2浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 2

I 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.

发布评论

评论列表(0)

  1. 暂无评论