ged_in() ) { $customer_logout = get_option( 'woocommerce_logout_endpoint', 'customer-logout' ); if ( ! empty( $customer_logout ) && ! empty( $items ) && is_array( $items ) ) { foreach ( $items as $key => $item ) { if ( empty( $item->url ) ) { continue; } $path = wp_parse_url( $item->url, PHP_URL_PATH ); $query = wp_parse_url( $item->url, PHP_URL_QUERY ); if ( strstr( $path, $customer_logout ) || strstr( $query, $customer_logout ) ) { unset( $items[ $key ] ); } } } } return $items; } add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_items', 10 ); /** * Fix active class in nav for shop page. * * @param array $menu_items Menu items. * @return array */ function wc_nav_menu_item_classes( $menu_items ) { if ( ! is_woocommerce() ) { return $menu_items; } $shop_page = wc_get_page_id( 'shop' ); $page_for_posts = (int) get_option( 'page_for_posts' ); if ( ! empty( $menu_items ) && is_array( $menu_items ) ) { foreach ( $menu_items as $key => $menu_item ) { $classes = (array) $menu_item->classes; $menu_id = (int) $menu_item->object_id; // Unset active class for blog page. if ( $page_for_posts === $menu_id ) { $menu_items[ $key ]->current = false; if ( in_array( 'current_page_parent', $classes, true ) ) { unset( $classes[ array_search( 'current_page_parent', $classes, true ) ] ); } if ( in_array( 'current-menu-item', $classes, true ) ) { unset( $classes[ array_search( 'current-menu-item', $classes, true ) ] ); } } elseif ( is_shop() && $shop_page === $menu_id && 'page' === $menu_item->object ) { // Set active state if this is the shop page link. $menu_items[ $key ]->current = true; $classes[] = 'current-menu-item'; $classes[] = 'current_page_item'; } elseif ( is_singular( 'product' ) && $shop_page === $menu_id ) { // Set parent state if this is a product page. $classes[] = 'current_page_parent'; } $menu_items[ $key ]->classes = array_unique( $classes ); } } return $menu_items; } add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_item_classes', 2 ); /** * Fix active class in wp_list_pages for shop page. * * See details in https://github.com/woocommerce/woocommerce/issues/177. * * @param string $pages Pages list. * @return string */ function wc_list_pages( $pages ) { if ( ! is_woocommerce() ) { return $pages; } // Remove current_page_parent class from any item. $pages = str_replace( 'current_page_parent', '', $pages ); // Find shop_page_id through woocommerce options. $shop_page = 'page-item-' . wc_get_page_id( 'shop' ); if ( is_shop() ) { // Add current_page_item class to shop page. return str_replace( $shop_page, $shop_page . ' current_page_item', $pages ); } // Add current_page_parent class to shop page. return str_replace( $shop_page, $shop_page . ' current_page_parent', $pages ); } add_filter( 'wp_list_pages', 'wc_list_pages' );