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)
In my opinion this is the simplest solution
$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
);
$product_categories = get_terms( 'product_cat', $cat_args );
if( !empty($product_categories) ){
echo '
';
foreach ($product_categories as $key => $category) {
echo '
- ';
echo '';
echo $category->name;
echo '';
echo '
';
}
echo '
';
}