There are some scenarios for adding php coded instead of shorcodes for displaying categories in woocommerce website We can use the below code for the same

<div class=”menu-categs-box”>
<?php $wcatTerms = get_terms(‘product_cat’, array(‘hide_empty’ => 0, ‘orderby’ => ‘ASC’, ‘parent’ =>0)); //, ‘exclude’ => ‘17,77’
foreach($wcatTerms as $wcatTerm) :
$wthumbnail_id = get_woocommerce_term_meta( $wcatTerm->term_id, ‘thumbnail_id’, true );
$wimage = wp_get_attachment_url( $wthumbnail_id );
?>
<ul>
<li class=”libreak”><?php if($wimage!=””):?><img src=”<?php echo $wimage?>”><?php endif;?></li>
<li>
<a href=”<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>”><?php echo $wcatTerm->name; ?></a>
<ul class=”wsubcategs”>
<?php
$wsubargs = array(
‘hierarchical’ => 1,
‘show_option_none’ => ”,
‘hide_empty’ => 0,
‘parent’ => $wcatTerm->term_id,
‘taxonomy’ => ‘product_cat’
);
$wsubcats = get_categories($wsubargs);
foreach ($wsubcats as $wsc):
?>
<li><a href=”<?php echo get_term_link( $wsc->slug, $wsc->taxonomy );?>”><?php echo $wsc->name;?></a></li>
<?php
endforeach;
?>
</ul>
</li>
</ul>
<?php
endforeach;
?>
</div>

Advertisements