How to get Woocommerce subcategory featured image in loop code?

In this post, we will discuss How to get Woocommerce subcategory featured image in loop code?. functions.php. So first download a file from your web server theme folder. Open it and paste the below code.

//get child categories woocommerce
function woocommerce_subcats_from_parentcat_by_ID($parent_cat_ID) {
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => $parent_cat_ID,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
echo '
    ‘; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); //echo ”

    ";
    //print_r(get_term_meta());
    //echo "

    “; $thumbnail_id = get_term_meta( $sc->term_id, ‘thumbnail_id’, true ); $image = wp_get_attachment_url( $thumbnail_id ); echo ‘

  • ‘.$sc->name.’
  • ‘; //echo $image; echo ‘' . $sc-name . '‘; } echo ‘

';
}

Now open front-page.php or any custom template where you want to display subcategory images. Paste the below code here.

On upper code here is woocommerce_subcats_from_parentcat_by_ID(46) and 46 is the main category id number here you can paste.

What's your reaction?
0COOL0WTF0LOVE0LOL