Answer the question
In order to leave comments, you need to log in
How can I display products from different categories on the main page in woocommerce?
Good afternoon.
Just started learning woocommerce.
I created several categories and attached several products to them.
Now you need to display in the order of the category name -> 5 products, and so 3 categories.
The problem is related to hooks.
I understand that I need to use the wp_query loop, but where should I insert the category name.
<?php do_action('woocommerce_before_main_content'); ?>
<?php
$products = new WP_Query(['post_type' => 'product', 'posts_per_page' => 6]);
?>
<?php if ($products->have_posts()): ?>
<?php while ($products->have_posts()): ?><?php $products->the_post(); ?>
<?php do_action('woocommerce_product_loop_start'); ?>
<?php wc_get_template_part('content', 'product'); ?>
<?php do_action('woocommerce_product_loop_end'); ?>
<?php endwhile; ?><?php wp_reset_postdata(); ?>
<?php else: ?><?php endif; ?>
<?php do_action('woocommerce_after_main_content'); ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question