Product categories in WooCommerce are a custom taxonomy know as product_cat
. I'm using get_categories
with the taxonomy parameter set to product_cat
. It worked perfectly buy how to get the link to display. Becasue get_category_link
is not working with custom taxonomy and get_term_link
, I am getting with my code
$prod_cat_args = array(
'taxonomy' => 'product_cat', //woocommerce
'orderby' => 'name',
'empty' => 0
);
$woo_categories = get_categories( $prod_cat_args );
foreach ( $woo_categories as $woo_cat ) {
$woo_cat_id = $woo_cat->term_id; //category ID
$woo_cat_name = $woo_cat->name; //category name
$return .= '<a href="' . get_category_link( $woo_cat_id ) . '">' . $woo_cat_name . '</a>';
}//end of $woo_categories foreach