From acea49175561f97aa059586ad1938acbae6cf700 Mon Sep 17 00:00:00 2001 From: Benjamin Conrad Date: Wed, 17 Jul 2024 17:30:17 +0200 Subject: [PATCH] Fix a bug where woocommerce removes the current-menu-item class (#45095) * Fix a bug where woocommerce removes the current-menu-item class from a menu item (e.g. taxonomy) because its id matches with page_for_posts option * Add changefile(s) from automation for the following project(s): woocommerce * Add changefile(s) from automation for the following project(s): woocommerce * Apply suggestions from code review Co-authored-by: Vedanshu Jain * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions Co-authored-by: Vedanshu Jain --- plugins/woocommerce/changelog/45095-trunk | 4 ++++ plugins/woocommerce/includes/wc-page-functions.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 plugins/woocommerce/changelog/45095-trunk diff --git a/plugins/woocommerce/changelog/45095-trunk b/plugins/woocommerce/changelog/45095-trunk new file mode 100644 index 00000000000..69a05875dc8 --- /dev/null +++ b/plugins/woocommerce/changelog/45095-trunk @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix a bug where woocommerce removes the current-menu-item class. #### Comment \ No newline at end of file diff --git a/plugins/woocommerce/includes/wc-page-functions.php b/plugins/woocommerce/includes/wc-page-functions.php index 2b0a03f05e8..3f307c50ec6 100644 --- a/plugins/woocommerce/includes/wc-page-functions.php +++ b/plugins/woocommerce/includes/wc-page-functions.php @@ -168,7 +168,7 @@ function wc_nav_menu_item_classes( $menu_items ) { $menu_id = (int) $menu_item->object_id; // Unset active class for blog page. - if ( $page_for_posts === $menu_id ) { + if ( $page_for_posts === $menu_id && isset( $menu_item->object ) && 'page' === $menu_item->object ) { $menu_items[ $key ]->current = false; if ( in_array( 'current_page_parent', $classes, true ) ) {