I need some food for thought on this because I have had trouble finding a decent solution here.
There is a woocommerce shop, categories on the left side (sidebar) and on the right side products. A product can have multiple categories; for example, the product "Burger" is in the categories "Food" and "Fastfood".
Now on the left side we have the categories "Food" and "Fastfood" with both "Burger" in them. I go to category "Food". On the left side in the sidebar I highlight the category food with:
(start loop going through categories)
if(get_query_var('product_cat') == $cat->slug) - echo <li class="active">
else - echo <li class="active">
(end loop)
so the category "Food" is highlighted. Then I select the product "Burger". Now, because the product "Burger" is also in the category "Fastfood", the category "Fastfood" is displayed as active.
The active category should be based on the category that the product was selected from originally ("Food"). If you go to the category "Fastfood" and select "Burger", then "Fastfood" should be active. Open "Burger" from "Food", "Food" should be the active category.
My attempt is to change the category in the permalink (<?php the_permalink(); ?>)
to the current category when displaying all the products, but it just doesn't feel like the right way.
Maybe someone has a better solution.
Wish you a good day!
EDIT:
I've managed to create the permalink with the right category:
$custom_permalink = get_settings('siteurl')."/".get_query_var('product_cat')."/".basename(get_permalink());
Sadly this does not work.. (redirects me to the "wrong" category) but I don't like this hack anyways :)..