Wednesday 15 June 2016

Applying Conditions to Menu For WooCommerce Subscribers







Have you been planning on starting up a WordPress powered membership site? Well, then you might have heard of the difficulties associated with creating membership sites with WordPress. Thankfully, building a membership site using WooCommerce can make the task considerably easier.

But remember, once you've created a membership site it's imperative that everything on your site oozes exclusivity for your logged-in users or WooCommerce subscribers. Thankfully, many plugins are available online that renders the ability to control the pages or portions of your website content that you want to show to active subscribers and hide from inactive subscribers.

Understanding the need to show/hide menu items


Of course, if you don't want certain pages to be accessed by non-members (or non-logged in users), you won't want those pages to be displayed in your site's navigation menu as well. Likewise, there will be some pages that might not be of much use to members. For instance, the pages that sell WooCommerce subscription products and/or services to guests aren't useful for active subscribers. And so, it's better to keep such pages hidden from the subscribers.
In essence, for a membership site, you should consider adding conditional logic to show or hide menu items based on user role. After all, it isn't a good practice to make your members (or active subscribers) shuffle around the content every time they visit your site. Rather, you should make it easy for your members to find quickly the features and services they've signed up for. In short, you must make your site's navigation menu more member focused.

So, what's the solution?

This is where the “If Menu” plugin comes in handy. The plugin helps in controlling the navigation menus for members. Through this tutorial, I'll help you learn how you can create a menu adjusted for your active WooCommerce subscribers. Also, you'll get to know about the plugin and how it can be used to determine whether a subscriber has an active or inactive subscription. In reference to this post, we'll be using the following two plugins:

  • If menu plugin
  • WooCommerce Subscriptions

Note: Before proceeding with the process of using both of the above mentioned plugins, make sure that they're installed on your site.

Let's get started

For adding conditional logic to menu items you'll need to configure:

  • Active or inactive roles of your WooCoomerce subscribers.
  • Menu items for members (i.e. active subscribers)
  • Menu items for guests (i.e. non-logged in users)

A list of sample memberships included in the image.



Let us now have a detailed overview of all the above listed key points one by one:


Step 1 – Configuring Active / Inactive Roles of WooCommerce Subscribers

Before you configure the menu items for your WooCommerce subscribers, you'll first need to set up the roles of active or inactive subscribers. For this purpose, click on the WooCommerce option from your WP admin navigation menu. Next, click on the Subscriptions tab, and from here set up the active/inactive subscribers roles.

Bear in mind; active subscribers are assigned the “Subscriber” role, and inactive subscribers are assigned the “Customer” role by default as shown in the below image:




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

Keep in mind that the roles we'll assign to active and inactive subscribers will help us in showing or hiding certain menu items.

Step 2 – Configuring Menu Items for Active WooCommerce Subscribers

So, now that you have set up the roles of active (and inactive) WooCommerce subscribers, next you need to decide which menu item you would like to show to your active subscribers. Here, we'll need to make use of the If Menu plugin.

The 'If Menu' plugin lets you show/hide your website primary navigation menu items on the basis of conditional statements, such as user roles, whether a user is logged-in or not, etc. But, to make use of the plugin, you'll first have to make sure that the plugin is enabled.

As soon as the plugin gets enabled, a new checkbox option labeled “Enable Conditional Logic” will be added to each menu item. For this, go to Appearance → Menus, and from there you can start making edits to your navigation menus.

Next, click on any of navigation menu item and then make the ‘Enable Conditional Logic’ checkbox checked. And then, you just need to select whether you would want to show or hide the selected menu item. You will then need to choose any one of the corresponding conditions from the drop down box.

Since we need to show particular menu item just to your active subscribers, we have to choose to show the “Subscriber-only” page link only if “User is Subscriber”:

Once you have selected a condition, just hit the “Save Menu” button.

Step 3 – Configuring Menu Items For Non-Logged in Users

In this section, we'll talk about the process of showing your menu items to guests (or non-logged in users) of your membership website. To do so, you just need to click on the “Hide” option if the corresponding condition is set to “User is logged in.”

Click here, to get more information about subscription


Wrapping Up

Apart from making your membership website pages or part of the content to members, you should also consider adjusting the navigation menu items based on user statuses. Doing so will save the time and efforts of your active subscribers directly shuffle through the useful pages that can be accessed by them. Likewise, you don't necessarily need to show the pages that cannot be accessed by guests or inactive subscribers.

Hope this post will guide you in controlling the navigation menu items of your WordPress membership site with utmost efficiency.

1 comment: