wc_nav_menu_items

Hide menu items conditionally.

Description

(array) wc_nav_menu_items( (array) $items ); 

Returns (array)

Parameters (1)

0. $items (array)
The items.

Usage

  1. if ( !function_exists( 'wc_nav_menu_items' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-page-functions.php'; 
  3.  
  4. // The items. 
  5. $items = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_nav_menu_items($items); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-page-functions.php  
  1. function wc_nav_menu_items( $items ) { 
  2. if ( ! is_user_logged_in() ) { 
  3. $customer_logout = get_option( 'woocommerce_logout_endpoint', 'customer-logout' ); 
  4.  
  5. if ( ! empty( $customer_logout ) ) { 
  6. foreach ( $items as $key => $item ) { 
  7. $path = parse_url( $item->url, PHP_URL_PATH ); 
  8. $query = parse_url( $item->url, PHP_URL_QUERY ); 
  9. if ( strstr( $path, $customer_logout ) || strstr( $query, $customer_logout ) ) { 
  10. unset( $items[ $key ] ); 
  11.  
  12. return $items;