Closed thomasjulienalain closed 1 year ago
I assume WooCommerce has a different name for the current-item
class on the shop. Can you possibly paste me the list of classes set on the menu item by default?
Hi there, i'm also experiencing the same thing. The menu item for WooCommerce's Shop page just shows "menu-item ".
Hey!
Stumbled across the same problem, seems like WooCommerce is adding the current-menu-item
class via the wp_nav_menu_objects
filter.
Maybe thats why it's not showing up as active? See here: https://github.com/woocommerce/woocommerce/blob/3ded2b46e976e5c11393a6cf70943b4f6ef14cb3/plugins/woocommerce/includes/wc-page-functions.php#L157
I used array_map
combined with some WooCommerce Conditionals to get this to work, but I guess it's not the cleanest solution.
In case anyone needs a quick workaround:
/**
* Returns the shop navigation.
*
* @return array
*/
public function navigation()
{
if (Navi::build('shop_navigation')->isEmpty()) {
return;
}
$shop_page = wc_get_page_id('shop');
$shopNav = Navi::build('shop_navigation')->toArray();
if (is_shop() || is_singular('product')) {
array_map(function ($item) use ($shop_page) {
$item->active = $shop_page == $item->objectId ? true : false;
return $item;
}, $shopNav);
}
return $shopNav;
}
Hey, not sure if something changed but I can't reproduce this with the latest WooCommerce. I'm getting active
items for Shop, Products, etc. without any issues.
If someone can show an example of it being broken, I have an easy fix– otherwise, I'm going to close this for now as I don't want to deploy the fix without knowing it's actually doing something.
Hi there, I am getting the same issue. The /shop page is setting to false the "active" boolean property. We are using the last WooCommerce version 8.7.0
Hello !
It's weird, when adding the WooCommerce's shop page in my menu, the item returned by navi has 'active' set to false when I am on the shop page.
Works fine for any other page.