I am trying to get the product categories from WooCommerce through a function in my WordPress theme
function get_me_list_of($atts, $content = null)
Improving Suman.hassan95's answer by adding a link to subcategory as well. Replace the following code:
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
echo $sub_category->name ;
}
}
with:
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
echo '
'. $sub_category->name .'';
}
}
or if you also wish a counter for each subcategory, replace with this:
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
echo '
'. $sub_category->name .'';
echo apply_filters( 'woocommerce_subcategory_count_html', ' ' . $sub_category->count . '', $category );
}
}