Хочу отобразить меню категории woocommerce, и отобразить возле него количество товаров.
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 1;
$pad_counts = 1;
$hierarchical = 1;
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
?>
<?php $all_categories = get_categories( $args );
// print_r($all_categories);
foreach ($all_categories as $cat) {
// print_r($cat);
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
?>
<?php echo $show_count; ?>
<?php echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>'; ?>
<?php
$args2 = array(
'taxonomy' => $taxonomy,
'child_of' => 0,
'parent' => $category_id,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
$sub_category_id = $sub_category->term_id;
echo '<br /><a href="'. get_term_link($sub_category->slug, 'product_cat') .'">'. $sub_category->name .'</a>';
//
$args3 = array(
'taxonomy' => $taxonomy,
'child_of' => 0,
'parent' => $sub_category_id,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$sub_two_cats = get_categories( $args3 );
if($sub_two_cats) {
foreach($sub_two_cats as $sub_two_category) {
echo '<br /><a href="'. get_term_link($sub_two_category->slug, 'product_cat') .'">'. $sub_two_category->name .'</a>';
}
}
//
}
} ?>
<?php }
}
?>
Ссылка на сайт