简体   繁体   中英

Get WooCommerce product terms for all products shown in a category

I've made a category in WooCommerce. In this category I've an amount of X products. All of my products has some terms.

Now I want to display all product related terms in my category from the available products there.

For example I've product A, B & C.

A has term: HB has term: KC has term: Z

Product A & C are in category 1. So I want just the terms H & Z shown in this category.

I've tried this here but this returns all available product terms, also from the products outside of the category:

$terms = get_terms('product_tag');

You will get the each products Ids inside your loop in category page.

So you can use that Product id in below code.

$terms = get_the_terms( $your_product_id, 'product_tag' );

You need to replace function get_the_terms instead of get_terms .

That way you will get the each products tag in category page. Try it and let me know if you have any issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM