I’m trying to get or list all category names or IDs of the current product in WooCommerce.
Using this code: I get whole links to the categories but I want their names or IDs.
<?php
// Get list of ALL categories for current product
$cats = wc_get_product_category_list( $id );
var_dump($cats);
?>
I want categories’ names or IDs so I can use them to iterate through.
2
Answers
Try this
Pase the following code in the
functions.php
file of the theme.Reference: https://developer.wordpress.org/reference/functions/wp_get_post_terms/