S
S
Sergey Burduzha2019-11-13 17:29:15
WooCommerce
Sergey Burduzha, 2019-11-13 17:29:15

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'); ?>

write before_main_content, and use wp_query to select products from one category, then close and write before_main_conent again and display products again?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yarovikov, 2019-11-13
@serii81

WP_Query

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question