I am trying to get the category name of a product (for example "nutrition", "sport", etc), but I can't.
I'm trying this way:
$test = wc_get_product_category_list(1202);
But what I get is the following:
<a href="https://example.es/product-category/nutricion/sustitutivos/nutricion-batidos/" rel="tag">Batidos</a>,
<a href="https://example.es/product-category/nutricion/" rel="tag">Nutrición</a>
I just need the tag "Batidos", "Nutrición"...
I would really appreciate any help, I've been trying and reading for a long time but I can't ...
Regards and thanks.
To get the product category name(s) from a product Id, use instead
wp_get_post_terms()
function:To get the product category name from a product category Id, use
get_term-by()
function as follows:Tested and works.