A
A
Alexander Bondarenko2020-09-24 14:59:45
WordPress
Alexander Bondarenko, 2020-09-24 14:59:45

How to get the current woocommerce category?

global $post;
$cat = get_the_category($post->ID);
var_dump( $cat );
echo $cat->slug;

I did as in the example , but the result is not displayed, what could be the problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-09-24
@bond_1013

have you tried get_queried_object() ?

$term = get_queried_object();
$slug = $term->slug;
echo $slug;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question