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 <vedanshu.jain.2012@gmail.com>

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Vedanshu Jain <vedanshu.jain.2012@gmail.com>
This commit is contained in:
Benjamin Conrad 2024-07-17 17:30:17 +02:00 committed by GitHub
parent ece00533e4
commit acea491755
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix a bug where woocommerce removes the current-menu-item class. #### Comment <!-- If the changes in this pull request don't warrant a changelog entry, you can alternatively supply a comment here. Note that comments are only accepted with a significance of "Patch" -->

View File

@ -168,7 +168,7 @@ function wc_nav_menu_item_classes( $menu_items ) {
$menu_id = (int) $menu_item->object_id; $menu_id = (int) $menu_item->object_id;
// Unset active class for blog page. // 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; $menu_items[ $key ]->current = false;
if ( in_array( 'current_page_parent', $classes, true ) ) { if ( in_array( 'current_page_parent', $classes, true ) ) {