woocommerce与此无关。
但下面的代码应该得到所有产品类别(以及子类别)。
只需将其放置在模板中(您希望类别显示在其中)
<?php
$taxonomy = \'product_cat\';
$hierarchical = 1;
$title = \'\';
$empty = 0;
$args = array(
\'taxonomy\' => $taxonomy,
\'hierarchical\' => $hierarchical,
\'title_li\' => $title,
\'hide_empty\' => $empty
);
$woo_categories = get_categories( $args );
foreach ($woo_categories as $cat) {
if($cat->category_parent == 0) {
$cat_id = $cat->term_id;
echo \'<br /><a href="\'. get_term_link($cat->slug, \'product_cat\') .\'">\'. $cat->name .\'</a>\';
$args1 = array(
\'taxonomy\' => $taxonomy,
\'child_of\' => 0,
\'parent\' => $cat_id,
\'orderby\' => $orderby,
\'show_count\' => $show_count,
\'pad_counts\' => $pad_counts,
\'hierarchical\' => $hierarchical,
\'title_li\' => $title,
\'hide_empty\' => $empty
);
$sub_categories = get_categories( $args1 );
if($sub_categories) {
foreach($sub_categories as $sub_category) {
echo \'<br /><a href="\'. get_term_link($sub_category->slug, \'product_cat\') .\'">\'. $sub_category->name .\'</a>\';
}
}
}
}
?>