Get WooCommerce product categories from WordPress




Geniuswp show

Summary: 176 This will list all the top level categories and subcategories under them hierarchically. do not use the inner query if you just want to display the top level categories. Style it as you like. edited Mar 10, 2016 at 9:25 subZero4,83766 gold badges2929 silver badges4949 bronze badges answered Jan 9, 2014 at 5:28 Suman.hassan95Suman.hassan953,70577 gold badges2424 silver badges2424 bronze badges 11 22 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 ); } } answered Sep 25, 2014 at 16:01 Xris PapXris Pap22122 silver badges33 bronze badges 9 You could also use wp_list_categories(); wp_list_categories( array('taxonomy' => 'product_cat', 'title_li' => '') ); answered Oct 28, 2019 at 19:49 Etienne DupuisEtienne Dupuis12.9k66 gold badges4545 silver badges5656 bronze badges 2... You are listening to the topic about "Get WooCommerce product categories from WordPress", if you want to read the full article, please visit https://geniuswp.com or the link in the description.