product taxonomy loop
Thu Oct 12 2023 19:58:26 GMT+0000 (Coordinated Universal Time)
Saved by
@naveedrashid
function product_cat_loop(){
$product_cat = get_terms('product_cat' , array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
// 'number' => 6,
));
?>
<div class="row product_cat_row">
<?php
if(!empty($product_cat) && ! is_wp_error($product_cat)):
foreach($product_cat as $category):
$thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true);
$thumbnail_url = wp_get_attachment_url($thumbnail_id);
if($thumbnail_url){
?>
<div class="col-md-2">
<div class="product_cat">
<div class="product_cat_img">
<?php if ($thumbnail_url) : ?>
<img src="<?php echo $thumbnail_url; ?>" alt="<?php echo $category->name; ?>">
<?php endif; ?>
</div>
<div class="product_cat_info">
<a href="<?php echo get_term_link($category); ?>">
<p><?php echo $category->name; ?></p>
<p><?php echo $category->count; ?> products </p>
</a>
</div>
</div>
</div>
<?php
}
endforeach;
endif;
?>
</div>
<?php }
content_copyCOPY
Comments