Would you like create a website to member area with WordPress?

Well, you are probably aware of the various difficulties encountered during this process. Fortunately, building a member's area website using WooCommerce can make the job a lot easier.

First take a look at how Create a WordPress member area

But remember, once you've created a member's area website, it is imperative that your website offers exclusives for connected users or WooCommerce subscribers.

In this tutorial, I will show you how to display menus based on the role of users.

But before you start, take the time to take a look at How to install a WordPress themeHow many plugins to install on WordPress.

Then let's get to work!

Understand the need to show or hide menu items

Of course, if you don't want certain pages to be accessible to users who are not logged in, then you won't want those pages to show in the navigation menu as well.

Likewise, there will be some pages which might not be of much use to members (e.g. pages that sell subscription products, which is unnecessary for already subscribed users) and therefore, it is better to keep these pages hidden from subscribers.

In essence, for a member's area website, you should consider adding conditional logic to show or hide items on the menu by considering the role of the user.

Step 1 - Configure Subscriber Roles

Before setting up menu items for your WooCommerce subscribers, you must first set the roles of active or inactive subscribers. This is a feature available with the WooCommerce extension " WooCommerce Subscriptions ". Then go to the WooCommerce settings then click on the subscriptions tab, this is where you will have to define the role of active and inactive subscribers.

Keep in mind that active users have the role "SubscriberAnd inactive subscribers have the role " client By default as shown in the image below:

WooCommerce subcription plugin WordPress for WooCommerce subscriptions

Note: You can also choose to set up custom roles for your subscribers, using WordPress plugins such as User Role Editor.

Keep in mind that the roles we are going to assign to active and inactive subscribers will help us show or hide certain menu items.

Go further in your reading by discovering How to restrict access to WordPress media to certain users

Step 2 - Configure Menu Items for Active WooCommerce Subscribers

So now that you have defined active roles (And inactive) of WooCommerce subscribers, you must decide which menu item you want displayed to your active subscribers. Here we need to use the “if menu” plugin menu.

The plugin " If menu »Allows you to show / hide your menus based on conditional statements, such as user roles, whether a user is logged in or not, etc. But before using the plugin, you will first need to make sure that the plugin is activated.

As soon as the plugin is activated, a new box " Enable Conditional Logic Will be added to each menu item. To do this, go to " Appearance → Menus And from there you can start making changes to your navigation menus.

Next, click on one of the navigation menus, then activate conditional logic. And then, you just need to choose whether you want to show or hide the selected menu item. You will then need to choose one of the corresponding conditions from the drop-down list that follows.

Since we need to display just menu items for active subscribers, we must choose the option " User is Subscriber ».

menu to display to subscribers only

Once you have selected a condition, simply press the " Save Menu". Now, each time the menu with a condition will be displayed when the condition is met.

WordPress subscribe menu if menu plugin

In the image above, you can see the variation between two menus for subscribed users and those who are not. You can also do the same for users who are not logged in.

Read also How to redirect users after login in WordPress

How to redirect a user when not logged in

You can add a redirect that will prevent the user from accessing a specific page when they do not meet certain conditions. Remember I showed you how to create a WordPress plugin. You'll need it to add the portion of code I'm going to provide.

I remind you that this method is intended for those who have a mastery of the PHP programming language.

add_action( 'admin_init', 'redirect_non_logged_users_to_specific_page' );

function redirect_non_logged_users_to_specific_page() {

if ( !is_user_logged_in() && is_page('identifiant-de-la-page-ou-slug') && $_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php' ) {

wp_redirect( 'http://www.example.com/page-de-destination/' ); 
    exit;
}

In this code, what you have to change is the name or the identifier of the page " ID-of-the-page-or-slug In the function « is_page "; and you must also define the destination address, in the function " wp_redirect ».

That's about all you need to know for this tutorial. Feel free to ask us questions in the comments form.

Discover also some premium WordPress plugins  

You can use other WordPress plugins to give a modern appearance and to optimize the handling of your blog or website.

We offer you here some premium WordPress plugins that will help you do that.

1. WordPress Video Gallery

WordPress Video Gallery is a very impressive video gallery plugin; just what is needed for your website. It is powerful, responsive, fast, and at the cutting edge of technology. However, this plugin is mainly distinguished by the fact that it is highly customizable. 

Video gallery wordpress plugin

So you have 5 different styles to match any branding image. And if that's not enough for you, you can generate your own style and color schemes. 

See also How to Create a Photo Gallery on Your WordPress Blog

With WordPress Video Gallery, enjoy multiple video galleries in one. Indeed, this WordPress Plugin premium sets up a gallery that streams its content from several other galleries. For example, you can create a gallery combined with a Vimeo channel + a YouTube playlist + some of your own videos.

Download | Demo | Web hosting

2. Sucuri

Sucuri is the best WordPress firewall and security plugin. As a website firewall, Sucuri has a built-in option that allows you to cache your website content and enable gzip compression with the click of a mouse.

Sucuri

See also How to protect your WordPress blog with a firewall

This is the best option for any website because Sucuri is a DNS level firewall. Which means it can serve the cached content to your users even before their request reaches your website.

This procedure gives your website an incredible improvement in performance.

Download | Demo | Web hosting

3. WordPress SMS Marketing Plugin

Ce WordPress Plugin marketing premium is specially designed to work with SMS.

Wordpress sms marketing wordpress plugin

As with most automated marketing tools, this allows you to streamline your marketing efforts through block programming, automated messages, trigger actions and more.

Discover our article on: BuddyPress and bbPress: Two WordPress plugins to maintain a conversation

It also comes with built-in analytics so you can see the results of your SMS marketing campaigns to see how well they are working.

Download | Demo | Web hosting

Recommended Resources

Find out about other recommended resources to help you build and manage your website.

Conclusion

Here ! That's it for this tutorial, I hope it allows you to display a conditional menu for your WooCommerce subscribers. Do not hesitate to share with your friends on your favorite social networks

However, you can also consult our resources, if you need more elements to carry out your projects of creation of Internet sites, by consulting our guide on WordPress blog creation.

If you have suggestions or remarks, leave them in our section Comments.

...