How to display products in the categories of card of woocommerce?

Guys tell me how to make a site map in a tree view. Regular pages, categories, posts - it's all clear. But bring in the same kind products woocommerce does not work.

the <ul>

$taxonomyName = "product_cat";
$prod_categories = get_terms($taxonomyName, array(
 'orderby'=--> 'name',
 'order' => 'ASC',
 'hide_empty' => 1
// Add categories you'd like to exclude in the exclude here
$cats = get_categories('exclude=');
foreach ( $prod_categories as $prod_cat ) {
 echo "<li><h3>Category: <a href="\"".get_category_link($prod_cat-">term_id)."\" target=\"_blank\" >".$prod_cat->name."</a></h3>";
 echo "<ul>";
 // here would display the products under each category...
 // query_posts('posts_per_page=-1&prod_cat='.$prod_cat->prod_cat_ID);
 // while(have_posts()) {
 // the_post();
 // $category = get_the_category();
 // // Only display a post link once, even if it's in multiple categories
 // if ($category[0]->prod_cat_ID == $prod_cat->prod_cat_ID) {
 // echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
 // }
 // }

 echo "</ul>";
 echo "</li>";

This code displays the product category, and the fact that is commented out displays the usual entry and not the products related to product category.
July 2nd 19 at 18:18
1 answer
July 2nd 19 at 18:20
1. Never use query_posts()
2. Instead of query_posts() in this case, use get_posts()
3. You forgot an additional parameter post_type=product, without it displayed post_type=post (default)
prompt please in what place you need to add parameter post_type=product, if here: $prod_categories = get_terms($taxonomyName, array(
'orderby'=> 'name',
'order' => 'ASC',
'hide_empty' => 1
nothing changes. - gunnar commented on July 2nd 19 at 18:23
: no, get_terms is to get terms, and after receipt and passage cycle on them, you need to get posts with those terms. Now you use the function query_posts which you should not use. Instead, it is necessary to use get_posts() or WP_Query with the same arguments + additional argument which I pointed out. - Velva.Rogahn commented on July 2nd 19 at 18:26

Find more questions by tags Internet shopsWooCommerceWordPress