如何获得Woocommerce产品的所有类别

时间:2019-07-12 13:38:32

标签: php wordpress woocommerce

您好,我想开发一个woo-commerce网站和JSON API,我想“获取产品的所有类别”

<?php
$terms = get_the_terms( '1753', 'product_cat' );
//$nterms = get_the_terms( '1753', 'product_tag' );

foreach( $terms as $term ) {
   $product_cat_id = $term->term_id;
   $product_cat_name = $term->name;
   break;
}

1 个答案:

答案 0 :(得分:0)

请尝试:

<?php
get_the_term_list( '1753', 'product_cat', '', ', ', '' ); ?> 

在此处检查参考: https://codex.wordpress.org/Function_Reference/get_the_term_list