This question comes from Emily:
How can I restrict products to members so that only members can purchase them? Our site is a club that only offers purchasing to registered members, and customers that aren’t members must sign up before they can purchase.
Unfortunately, most people want to be able to list products in their shop catalog so that non-members can see them, but limit purchasing only to members. You can obviously do this with custom code, but finding a solution that works as-is is difficult. It can be done using Exchange (which we have an upcoming tutorial on), but the ability to hide products from non-members is fairly easy.
Let’s go through how you can restrict products to members only and prevent access to them from non-members using the Groups plugin and the Groups 404 Redirect, both of which are free plugins. Members will still be able to see and purchase these products normally, but non-members can be blocked from them (products will be hidden) and redirected to a signup page.
Restricting Products to Members Only
First, let’s see what needs to be done with Groups. When you install the plugin, you’ll want to go to the Groups > Options page to ensure that you’re able to restrict products. As most eCommerce plugins add your products as custom post types, Groups will be be able to restrict access to them. For example, Groups has noticed that I’m using Easy Digital Downloads on one test site, and allows me to restrict my Downloads if desired:
Side note: this is really handy for restricting access to media files as well if this is something you need.
Make sure that your “Downloads” or “Products” post types can be restricted so that we’ll be able to enforce access restrictions on our products.
Next, you’ll want to make sure you have the right capabilities accessible. Add a capability for your members by going to Groups > Capabilities and clicking “New Capability”. For example, I created “basic”, “silver”, and “gold” capabilities, which correspond to my membership level access levels I’ve already created in my membership plugin (this is important – we’ll need to tie these capabilities and groups to the appropriate members later). If you’re using WooCommerce or Jigoshop, Groups probably is your membership solution, so you won’t have to worry about this.
Now create a group. This group can be assigned the capabilities you just created. I made Basic Members, Silver Members, and Gold Members groups. As I’m using a tiered membership, basic members only have the “basic” access capability, silver members have “basic” and “silver” access capability, and gold members have access to all capabilities.
Go back to the Options page. Scroll down to “Capabilities” and ensure that you can limit access using the new capabilities you’ve just created. This will make sure you can select the appropriate capability on the product page.
Now that you have restriction capabilities set up, you can add them to your products. In your product page, you’ll now see a meta box for Access restrictions. If you enable the appropriate capability restriction for this product, non-members will not be able to view the product. As I only want Gold Members to be able to purchase restricted products, I’ll only add that capability.
If you’re using Groups for WooCommerce, you can also bulk add restriction rules from the “Products” page by checking the products you want to restrict, then bulk-adding restrictions:
Awesome! Really easy.
There’s just one teeny-tiny problem. Non-members can’t see anything, so if they try to visit your product page from a link or elsewhere on your site, they’ll just see your 404 page. We’ll have to make sure we create a landing page and send them there instead so they can purchase a membership.
Setting up a Landing Page for Non-members
This is where the Groups 404 Redirect plugin will come in. First, make a landing page to send users to when they don’t have the correct access level to purchase a membership. Unfortunately, you can’t change where members are redirected depending on which level is required, so you’ll have to have one descriptive landing page for all of your membership levels. Obviously, you could customize this with some custom code, but this may work for many of you in the meantime. If you’re only using one membership level for restricting product purchasing, that’s probably not relevant for you. Carry on smile .
I’ve set up a quick sample page where I’ve linked to product pages for each membership, but you may want to include details about each membership so customers can quickly find the right one:
Pay attention to the
post_id for this page – you can find it really easily by looking at the URL in your address bar while you’re viewing it. You’ll see something like this:
http://test.com/wp-admin/post.php?post=428&action=edit. The part that says
?post=428 is what I need.
Now we’ll set up the redirect to this page. Make sure the Groups 404 plugin is installed, then go to Settings > Groups 404 and enter this ID for the redirection:
That’s it! Once you do this, customers will be directed to this landing page instead of a 404 page if they try to view a product they can’t purchase.
There’s one more thing we’re forgetting before we’re done – can you guess what it is?
Tying Groups to Members
Final step – technically everyone right now is a non-member, as you don’t have anyone assigned to your groups. If you’re using Groups for WooCommerce or Groups for Jigoshop, this is already done for you when customers purchase access to your membership group. You tie groups access to your WooCommerce or Jigoshop products when created, so purchasing triggers addition to the appropriate group.
If you’re using a different eCommerce and/or membership plugin, you’ll need to tie group access to the appropriate members since it doesn’t happen upon purchasing a membership.
Go to the “Users” menu. Unfortunately, we’ll have to do this manually and keep adding groups to new members manually if you use something other than WooCommerce or Jigoshop + Groups. If you have tons of members, you can hire a developer to customize this process to add groups automatically to membership purchases since the development costs will probably make sense for you to automate this process.
You can add groups to individual users by viewing the user’s profile and adding a group at the bottom:
You can also do this in bulk (which I’d recommend) by selecting the users that require this purchasing group, then using the bulk Groups actions at the top of the page:
I’m bulk-adding every person that’s bought a gold membership (I got a list of gold members in my membership plugin) to my gold-level purchasing group to sync this up with my product restriction.
Now your members are tied to the appropriate purchasing group, and these members will be able to view your protected products when logged in, while non-members cannot.
Take it Further
You could get a bit trickier with this to show restricted products in your catalog by creating a public product to show in your catalog, then redirecting that to a private one. For example, you could set up the public product as an external/affiliate product, then link to the restricted product. FYI, there’s a free EDD add-on for this.
This way, non-members see something in your catalog and are redirected to a signup page, while members will just be able to purchase. Unfortunately, this means members that are logged in will see both products in the catalog, so it’s not exactly ideal either.
This tutorial and usage doesn’t provide the smoothest solution to this problem, but it’s a free one that anyone can set up to restrict their products to members only using almost any eCommerce plugin.