How to Display woocommerce Products by custom code

In this tutorial, we discussed how to display woocommerce products with your custom HTML or with a simple layout.

The Basic Code

//developers guidance <?php $params = array('posts_per_page' => 5, 'post_type' => 'product'); $wc_query = new WP_Query($params); ?> <?php if ($wc_query->have_posts()) : ?> <?php while ($wc_query->have_posts()) : $wc_query->the_post(); ?> <?php the_title(); ?> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php else: ?> <p> <?php _e( 'No Products'); ?> </p> <?php endif; ?>

Display Woocommerce Products category wise:

The below code help to display the woocommerce products

<?php $products = wc_get_products(array('category' => array('category_slug'),); foreach ($products as $value) {?> <?php } ?>

You can add more conditions as per the requirement in-display woocommerce products.<…

Read more
  • 0