Looking to loop through WooCommerce categories outside the products page in WordPress? All you may need is to use get_categories() in a foreach PHP loop.
2 answers
1
Looping through WooCommerce categories
To loop through WooCommerce categories outside the products page in WordPress, use the code below.
<?php
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false
);
foreach( get_categories( $args ) as $category ) :
//do category data
endforeach;
?>— Support WizardAnswer 1
0
Excluding WooCommerce categories
To exclude certain categories, you can pass the exclude argument through the argument’s array.
$args = array( 'taxonomy' => 'product_cat', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false 'exclude' => array(1, 2, 3) //category IDs to exclude );
— Support WizardAnswer 2