Creating members-only content

One of the many uses of WooCommerce is to create a membership site. Using a few extra plugins, you can create premium content that's only available to users who have purchased the correct products from your site. The nice thing about this setup is that, if you want your membership site to sell any products, it's really easy to add that functionality, whereas a typical membership plugin will only allow memberships.

Getting ready

You must have WooCommerce Subscriptions, Groups (free-of-charge on WordPress.org), and Groups for WooCommerce (premium, available at WooThemes.com) installed and activated on your site. You should also have a Simple subscription product already created.

How to do it…

We're going to use a free plugin called Groups, which allows us to group our users and restrict content to specific groups. After creating the groups and the content, we'll be connecting a product to a group with Groups for WooCommerce.

  1. In the WordPress admin, click on Groups.
  2. Go to Groups | Capabilities.
  3. Click on New Capability.
    How to do it…
  4. Add a name for this capability. Something like Read premium posts is a pretty good name.
    How to do it…
  5. Click on the Add button.
  6. Click on New Group.
    How to do it…
  7. Enter a Name for the group.
  8. Enter the name for your group such as Premium Content will work well.
    How to do it…
  9. Click on the Save button.

We've created a group and a capability. We need to tell Groups that this capability can be used to restrict access.

  1. Go to Groups | Options.
  2. Under Capabilities, add the new capability we have created.
    How to do it…

At this point, we've created a group, created a capability, assigned that capability to a group, and told Groups the capability can be used to restrict content. Let's create a page that only that group can access:

  1. Go to Pages | Add New.
  2. Add a title and content as you would on any other WordPress page.
  3. In the sidebar, you should see an Access restrictions panel. Here, you can enter the capability you have created.
    How to do it…
  4. Click on Publish.

Alright. At this point, we've successfully restricted the page to our premium group.

Note

If you log out of your site and try again, there should be no way for you to access the page. It shouldn't appear in the menus and, if you access the URL directly, you should hit a 404 page.

Now we need to connect a product to the group we have created.

  1. In the WordPress admin, click on Products and navigate to an existing subscription product in your store.
  2. Scroll down to the Product Data panel.
  3. Click on the Groups tab.
  4. In the Add to Groups field, enter the name of the group you created earlier.
    How to do it…
  5. Click on Update to save the product.

Note

The product itself won't mention anything about the Group or the special privileges you added. The benefits of being a member should be typed in manually.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset