Offer special “members-only” products that require the user to have an active membership in order to purchase. The selected products can still appear in your Shop page or can be hidden from non-members.
You can optionally add a second recipe to redirect users away from the single product page when membership requirements are not met.
About the Recipe
This customization recipe allows you to restrict the purchase of products in designated WooCommerce product categories for active members only. You now have full control over which categories require a membership in order to be purchased and which product categories (if any) are available to the public, regardless of their membership status.
This recipe can be used on its own or in conjunction with our WooCommerce Integration Add On, which offers additional features for integrating Paid Memberships Pro with WooCommerce.
Suggested Use Cases For This Method
- A shop that offers an array of products, some of which will only relate to members. This can include products like Membership-branded clothing or accessories, access to digital add-on products, specialized meal or diet plans and more. Basically, anything that you only want your members to be able to own and purchase.
- A shop that offers unique or special products that can entice users to sign up for a membership in order to purchase. This can be an added incentive to users thinking about signing up for your membership.
Pro Tip: Try to make your membership level/products as easy to sign up for and purchase as possible. A user may feel reluctant to join a membership only to be able to purchase a particular product. This can leave them feeling “forced” into something that they do not want to be a part of.Look at offering a lot of value for your membership packages and rather use this as an “added benefit” instead of a means to purchase a product.
The Code Recipe
Update lines 17 to 19 with your site’s protected product categories. You can also restrict purchase to specific membership level IDs by updating the pmpro_hasMembershipLevel
function on line 11.
Restrict Product Access and Hide Products from the Shop
Here are two additional recipes for WooCommerce sites that want to hide certain members-only products on the site.
The first recipe is designed to redirect non-members away from any products in the “members-only” category. You can change this category to the appropriate category slug for your site by updating line 30 in the code below.
This second recipe will remove products with particular category from the WooCommerce shop loop. Only members that are logged in and meet the requirements of your recipe will see protected products in the shop area. Update line 28 with the array of category slugs you would like to exclude from the main shop loop.
Adding the Recipe to Your Website
You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.
Free Course: Membership Site Development—The Basics
Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.