Answer the question
In order to leave comments, you need to log in
How to make division into categories and subcategories in WooCommerce?
It is necessary to make a division of categories on the WooCommerce site, a division like on https://www.tools.by/
Maybe there is some kind of plugin or something like that. Split so that there is no web of goods on the main page.
Answer the question
In order to leave comments, you need to log in
Such a list of categories is quite simple to make. I practically don't use plugins, but I can show you the code on the basis of which you can implement this
. so that they have a common key
$taxonomy = 'category';
$args = [
'taxonomy' => $taxonomy, // название таксономии с WP 4.5
'hide_empty' => false,
];
if ( $terms = get_terms( $args ) ) {
$output = array();
foreach ( $terms as $key => $term ) {
if ( $term->parent == 0 ) {
$output[$term->term_id]['parent']['title'] = $term->name;
$output[$term->term_id]['parent']['link'] = get_term_link( $term->term_id, $taxonomy );
} else {
$output[$term->parent]['children'][$key]['title'] = $term->name;
$output[$term->parent]['children'][$key]['link'] = get_term_link( $term->term_id, $taxonomy );
}
}
}
if ( isset( $output ) && is_array( $output ) && !empty( $output ) ) {
foreach ( $output as $key => $items ) {
echo '<h2 class="title"><a href="' . $items['parent']['link'] . '" class="title-link">' . $items['parent']['title'] . '</a></h2>';
if ( isset( $items['children'] ) ) {
echo '<ul class="list">';
foreach ( $items['children'] as $key => $item ) {
echo '<li class="list-item"><a href="' . $item['link'] . '" class="list-link">' . $item['title'] . '</a></li>';
}
echo '</ul>';
}
} // end foreach
} // end if
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question