Last active
June 1, 2020 22:24
-
-
Save amouratoglou/1d8c7722239589c6c241435a24d62b6a to your computer and use it in GitHub Desktop.
Wp Woocommerce Subcategory Loop showing featured image in tumbnail size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// function can be placed in functions.php and then you can use on template files | |
// the following function, passing the ID of parent category | |
woocommerce_subcats_from_parentcat_by_ID($parent_cat_ID); | |
function woocommerce_subcats_from_parentcat_by_ID($parent_cat_ID) { | |
// custom parameters | |
$args = array( | |
'hierarchical' => 1, | |
'show_option_none' => '', | |
'hide_empty' => 0, | |
'parent' => $parent_cat_ID, | |
'taxonomy' => 'product_cat' | |
); | |
$subcats = get_categories($args); | |
echo '<ul class="wooc_sclist"> <div class="collapse_tabs">X</div>'; | |
foreach ($subcats as $sc) { | |
$link = get_term_link($sc->slug, $sc->taxonomy); | |
$thumbnail_id = get_woocommerce_term_meta($sc->term_id, 'thumbnail_id', true); | |
// to get the small size featured image of sub-category use | |
// use wp_get_attachment_thumb_url | |
$image = wp_get_attachment_thumb_url($thumbnail_id); | |
echo '<li class="list_item_product_menu"><a href="'. $link .'">' | |
?> | |
<img src="<?php echo $image; ?>" width="152" height="245" /> | |
<span class="product_name"><?php echo $sc->name; ?></span> | |
<span class="product_description"> | |
<?php echo category_description($sc->term_id); ?> | |
</span> | |
<?php | |
echo'</a></li>'; | |
} | |
echo '</ul>'; | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment