【发布时间】:2015-07-28 06:40:38
【问题描述】:
我正在尝试从产品 ID 中检索相关类别。 假设我有如下类别。
iPhone (Parent Category)
-iPhone 3 (sub)
-iPhone 4 (sub)
-iPhone 5 (sub)
-iPhone 6 (sub)
如果是产品:iPhone 4 充电器。 (在 iPhone 4 子类别中)
如何按产品 ID 检索以上所有类别(iPhone 4 充电器) 作为一个列表?
我觉得 Step 可能是 == (get product id) --> (get category) --> (get parent category) --> (get the category list of this parent category)
我正在尝试下面的代码
<?php
$parent = get_category_parents( $cat, true, ' » ' );
echo $product->get_categories( ', ', '<span>' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post->ID, 'product_cat' ) ), 'woocommerce' ) . ' ', '.</span>' );
?>
【问题讨论】:
-
您在使用 woocommerce 吗?什么产品??
标签: php wordpress woocommerce