Answer the question
In order to leave comments, you need to log in
How to display subcategories under category name in woocommerce?
How to display subcategories with images under the category name?
Like this:
Answer the question
In order to leave comments, you need to log in
<?php
$parentid = get_queried_object_id();
$args = array(
'parent' => $parentid,
'hide_empty' => false
);
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<div class="subcat-product"><ul class="subcat-product__content">';
foreach ( $terms as $term ) {
$thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
echo '<li class="subcat-product__item">';
//woocommerce_subcategory_thumbnail( $term );
echo '<a href="' . esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . ' catalog-list-block__title">';
echo '<img style="background-image: url('. wp_get_attachment_url( $thumbnail_id ) .')!important;background-size: 100%;background-repeat: no-repeat;background-size: cover; width: 100px; height: 100px;" />';
echo $term->name;
echo '</a>';
echo '</li>';
}
echo '</ul></div>';
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question