How I can make the subcategory features thumbnail clickable in WordPress

Viewed 42

I'm using this function to display wooCommerce subcategories and products in separate lists My problem is that it only makes the subcategory name a clickable link, and I want also the thumbnail image to be clickable and link to the actual category. How can I achieve that? Thanks.

function tutsplus_product_subcategories( $args = array() ) {
    $parentid = get_queried_object_id();

$args = array(
    'parent' => $parentid
);

$terms = get_terms( 'product_cat', $args );

if ( $terms ) {
    echo '<ul class="product-cats">';

    foreach ( $terms as $term ) {
        echo '<li class="category">';                 
            woocommerce_subcategory_thumbnail( $term );
            echo '<h2>';
                echo '<a href="' .  esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
                    echo $term->name;
                echo '</a>';
            echo '</h2>';
        echo '</li>';
    }

    echo '</ul>';
}

}
0 Answers
Related