F
F
Forsaider2016-05-23 15:57:58
WordPress
Forsaider, 2016-05-23 15:57:58

woocommerce. How to display one product from each category?

There is such a structure of categories in the store
- Category 1
- Subcategory 1
When I am in this category, I display products from subcategories 2, 3, 4 using woocommerce. But I do not show subcategories 2, 3, 4.
--- Subcategory 2
--- Subcategory 3
--- Subcategory 4
We need to make sure that only 1 product is displayed from each subcategory (2, 3, 4).
How can this be implemented?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Forsaider, 2016-05-23
@Forsaider Автор вопроса

id категории получаю таким образом:

global $product; //Если не объявлен ранее. Не уверен в необходимости.
global $post;
$categories = get_the_terms( $post->ID, 'product_cat' );
foreach ($categories as $category) {
 echo $category->term_id; //Может быть в нескольких категориях
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question