From f7baef9938deaad039037f6287b6ad24162d97f2 Mon Sep 17 00:00:00 2001 From: Khan M Rashedun-Naby Date: Tue, 15 May 2018 08:08:18 +0600 Subject: [PATCH] wc_list_pages function refactored --- includes/wc-page-functions.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/includes/wc-page-functions.php b/includes/wc-page-functions.php index c6f8e4f7b92..1b6c8220cd3 100644 --- a/includes/wc-page-functions.php +++ b/includes/wc-page-functions.php @@ -204,21 +204,21 @@ add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_item_classes', 2 ); * @return string */ function wc_list_pages( $pages ) { - if ( is_woocommerce() ) { - // 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. - $pages = str_replace( $shop_page, $shop_page . ' current_page_item', $pages ); - } else { - // Add current_page_parent class to shop page. - $pages = str_replace( $shop_page, $shop_page . ' current_page_parent', $pages ); - } + if ( ! is_woocommerce() ) { + return $pages; } - 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' );