Shortcode vypíše seznam podkategorií pro aktuální zadanou kategorii. Atribut parent_cat musí být ID kategorie, ne slug.
<?php
function gog_category_list($atts) {
extract(shortcode_atts(array(
'parent_cat' => get_queried_object_id()
), $atts));
if (is_search()) {
return;
}
// get category id in product archive page
$terms = get_terms(array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'parent' => $parent_cat
));
if ($terms) {
$i = 0;
echo '<ul class="category-list">';
foreach ($terms as $term) {
echo '<li class="category-item category-' . $term->term_id . ($term->term_id == $active_cat_id ? ' active' : '') . '">';
echo '<a href="' . esc_url(get_term_link($term)) . '" class="' . $term->slug . '">';
echo '<span class="category-item-title">' . $term->name . '</span>';
echo '</a>';
echo '</li>';
$i++;
}
echo '</ul>';
}
}
add_shortcode('category_list', 'gog_category_list');
<?php
function gog_archive_category_list() {
echo gog_category_list();
}
add_action('woocommerce_archive_description', 'gog_category_list', 20);