[英]Get all attributes with their terms related to a product category in Woocommerce
[英]Get WooCommerce product terms for all products shown in a category
我在WooCommerce中做了一個類別。 在這個類別中,我有X個產品。 我所有的產品都有一些條款。
現在,我想從那里的可用產品中顯示我的類別中所有與產品相關的術語。
例如,我有產品A,B和C。
A有條件:HB有條件:KC有條件:Z
產品A和C屬於類別1。因此,我只希望此類別中顯示的術語H和Z。
我在這里嘗試過,但這會返回所有可用的產品字詞,也來自類別之外的產品:
$terms = get_terms('product_tag');
您將在“類別”頁面的循環中獲得每個產品ID。
因此,您可以在以下代碼中使用該產品ID。
$terms = get_the_terms( $your_product_id, 'product_tag' );
您需要替換函數get_the_terms
而不是get_terms
。
這樣,您將在類別頁面中獲得每個產品標簽。 嘗試一下,讓我知道您是否有任何問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.