我正在开发一个Woocommerce商店,其产品按照品牌,颜色,尺寸等父类别进行组织 . 每个顶级类别都有许多子类别:例如,颜色的子类别包括红色,蓝色,粉红等
客户希望在正面和存档页面的网格/循环视图中的每个产品缩略图下方显示每个产品的品牌和尺寸(产品是鞋子) .
每种产品只有一个品牌,但可能有多种尺寸 .
基本上,我需要知道是否有一种方法只显示单个产品的特定子类别的 Headers ,如下所示:
[Product Thumbnail here]
[Price info here]
Brand: Nike
Size(s): 8, 8.5, 9
我只需要subcat Headers ,而不是链接 . 我知道对此的解决方案可能涉及调用content-product.php中的get_terms()函数,但我无法弄清楚如何仅列出产品的特定子类别 .
我正在寻找的代码基本上会说:
If this product is in the Brand category,
Then show its subcategory.
If this product is in the Size category,
Then show its subcategories.
1 回答
检查此链接:
https://developer.wordpress.org/reference/functions/get_terms/
并将此代码粘贴到您的商店页面中