How to Add Menu by User Roles in WooCommerce?

You can customize your website menus for different users, including non-logged-in users, B2B users, wholesalers, retailers, and other VIP user roles. By selecting user roles, you can choose to show/hide the complete menu or just a few of its items.

After your efforts to create the ideal navigation for your WordPress site, the next item on your to-do list should be determining how much of your website’s menu should be exposed to customers. In this article, we will guide you on how to add menu by user roles in your WooCommerce store.

Add Menu by User Roles in WooCommerce – Methods

There are two basic methods to add menu by user roles in WooCommerce.

  1. WooCommerce Menu by User Roles by Addify
  2. Add Menu by User Roles in WooCommerce Programmatically

Comparison of Both Methods

FeaturesProgramming SolutionMenu by User Role by Addify
Create multiple menusNoYes
Show different menus to different rolesNoYes
Hide menu partiallyNoYes
Hide by each menu itemNoYes
Compatible with WordPressYesYes
Hide Menu by user roleYesYes

Method #1: WooCommerce Menu by User Roles by Addify

Menu by User Roles for WooCommerce allows you to restrict menu or individual items for specific user roles. You can choose to create multiple menus and assign menu items to these menus bars. It is a perfect plugin for B2B and B2C merchants to personalize your websites.

Installation

  • To begin installation, look for a .zip file from your WooCommerce account and proceed with the download.
  • On the WordPress Admin Panel, go to Plugins and click on Add New. Upload your plugin here by choosing the downloaded file.
  • Click on Install Now and then Activate.

Setup and Configuration

As you activate the plugin, you can view the new “Menu by user roles” section under the WooCommerce admin panel. Click to configure.

The WooCommerce Menu by User Roles offers 2 different configuration options:

  • Restrict menus by user roles
  • Restrict menu items by user roles

Restricting Menus by User Roles

WooCommerce Menu by User Roles enables you to assign menus to specific user roles or guest customers. 

Navigate to WordPress Admin Panel > Settings > Menu by User Roles. In this section, you can assign any menu to any user role.

Menu by user role for woocommerce

Restrict Menu Items by User Roles

With this plugin, you can manage individual items in the menu by user roles. To enable this, navigate to Appearance > Menus. An option to allocate the menu to guests or particular user roles can be found next to each menu link. Only certain users will be able to see the menu items. The menu item will be displayed to all customers by default if none of the options are chosen.

Menu by user role for woocommerce

Create Unlimited New Menu Bars

WooCommerce Menu by User Roles also gives the option to create unlimited new menu bars. You can also assign pages/items to each menu.

Menu by user role for woocommerce

Method #2: Add Menu by User Roles in WooCommerce Programmatically

Let’s take a look at the program-based implementation of WooCommerce Menu by User Roles.

// Set or unset items

add_filter( 'wp_nav_menu_items', function( $items, $args ) {

if ( is_user_logged_in() ) {

$user_role = current( wp_get_current_user()->roles );

} else {

$user_role = 'guest';

}

if( in_array( $user_role, array('guest','subscriber','customer') ) ) {

unset( $items['bar'] );

unset($items['hello'] );

return $items;

}

}, 10, 2 );

Wrapping Up

Why have universal menus if you have different types of users? It’s essential to customize menus for each of your visitors, especially if you manage a membership website. It’s not necessary for new visitors to your website to view the same sidebar content as returning customers. Similar to this, it makes sense to show distinct content to users who are logged in to your site as compared to users who are not.

For further queries on this guide, feel free to reach out any time.

Avail The Oppurtunity

Subscribe to Our Updates and Newsletters.