I am trying to create custom dynamic menu for Woocommerce, and it seem I am stuck. To mark my categories as active, I need category ID of a page that I am in at the moment.
If I am in a category I get id like this:
if (is_product_category()) {
global $wp_query;
$curent_Cat_ID = $wp_query->get_queried_object()->term_id;
}
But it wont show anything on a product page. Is there a way to get category id on a product page? What I was able to find wasn't working anymore. Or somehow get an array like breadcrumbs with IDs?
global $product;
and$term_ids = $product->get_category_ids();
which gives an array of product category terms Ids. Or you can even use$terms_ids = wp_get_post_terms( get_the_ID(), 'product_cat', array( 'fields' => 'ids' ) );
– LoicTheAztec