I’m using the WooCommerce plugin with WordPress and within my theme I’d like to list all categories within a navigation menu with PHP.
I’ve tried using woocommerce_product_categories();
but I don’t want the images, or other HTML elements, just their names (and maybe permalinks).
How can I get that data?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
taken from that very same function:
// prior to wordpress 4.5.0
$args = array(
'number' => $number,
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
'include' => $ids
);
$product_categories = get_terms( 'product_cat', $args );
// since wordpress 4.5.0
$args = array(
'taxonomy' => "product_cat",
'number' => $number,
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
'include' => $ids
);
$product_categories = get_terms($args);
will give you the list of product categories. easy!
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0