aiwoo_exclude_menu_items

The WooCommerce Menu Extension aiwoo exclude menu items function.

Description

aiwoo_exclude_menu_items( $menu_item ); 

Parameters (1)

0. $menu_item
The menu item.

Usage

  1. if ( !function_exists( 'aiwoo_exclude_menu_items' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-menu-extension/woocommerce-menu-extension.php'; 
  3.  
  4. // The menu item. 
  5. $menu_item = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = aiwoo_exclude_menu_items($menu_item); 
  9.  

Defined (1)

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

/woocommerce-menu-extension.php  
  1. function aiwoo_exclude_menu_items( $menu_item )  
  2. $hide_children_of = array(); 
  3.  
  4. // Iterate over the items to search and destroy 
  5. foreach ( $menu_item as $key => $item ) { 
  6.  
  7. $visible = true; 
  8.  
  9. // hide any item that is the child of a hidden item 
  10. if( in_array( $item->menu_item_parent, $hide_children_of ) ) { 
  11.  
  12. $visible = false; 
  13. $hide_children_of[] = $item->ID; // for nested menus 
  14.  
  15. // check any item that has NMR roles set 
  16. if( $visible ) { 
  17. if($item->condition == 1) { 
  18. if(!is_user_logged_in()) { 
  19. $visible = false;  
  20. }else{ 
  21. $visible = true; 
  22.  
  23. // unset non-visible item 
  24. if ( ! $visible ) { 
  25. $hide_children_of[] = $item->ID; // store ID of item 
  26. unset( $menu_item[$key] ) ; 
  27.  
  28. return $menu_item;