Вы можете использовать так:
<?php
$taxonomy = 'product_cat';
$orderby = 'title';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 1;
$order = 'ASC';
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty,
'order' => $order,
'parent' => 0
);
$terms = get_categories( $args );
foreach ($terms as $term) { //Cycle through terms, one at a time
// Check and see if the term is a top-level parent. If so, display it.
if($term->category_parent == 0){
$term_id = $term->term_id; //Define the term ID
$term_link = get_term_link( $term, $taxonomy ); //Get the link to the archive page for that term
$term_name = $term->name;
echo '<a class="ccats" href="' . $term_link . '"><span class="label">' . $term_name . '</span></a>';
}
}
?>