In this post, you will learn how to restrict WooCommerce products to users who purchased another product.
This can be very useful for selling accessories such as keyboards or tablet protectors. Users must first purchase the tablet in order to buy the accessories. Of course, this is just an example. You can apply this same conditional restriction for any e-commerce business.
You can use WooCommerce products as if they were coupons to access other products. You can set a specific product as a prerequisite for buying another product. In other words, you’ll restrict products based on the purchase or ownership of another WooCommerce product.
We’ll use the WordPress Conditional Post Restrictions plugin.
With this WordPress plugin, you can apply any type of conditional restrictions to the following post types:
-
- Posts
- Pages
- Products
- Downloads
- Recipes
- Courses
- Events
- Forums
- And any other custom post type.
You can download the plugin here:
Download WordPress Conditional Post Restrictions Plugin - or - Read more
Once you install and activate the WordPress Conditional Post Restrictions, you’ll need to follow these steps to restrict products if a user hasn’t purchased another product.
1- How to restrict a product if the user hasn’t purchased another product
In this section, we show you how to easily restrict an individual product if a user hasn’t purchased another product. We’ll set a product as a prerequisite to purchasing another product.
Just follow the steps in this section:
- Go to Products > All products in wp-admin.
- Open the product you want to edit.
Once you open the product you want to edit, you scroll down to the Restriction rules section and select the following values:
- Enable content restrictions: Yes
- What happens when the conditions are met: Allow access
- Condition 1: User has purchased product = Product
- You select the product you want to set as a prerequisite to purchasing this product.
- To add more products, click + to add a new condition to the same group.
- To add another product as an option, click Add ‘Or’ group and select the condition.
- Update the product to save the changes.
This is how you can restrict individual products for users who haven’t purchased a specific product.
2- How to restrict an entire category to users who purchased another product
Instead of editing products one by one, you can restrict an entire category and set a product as a prerequisite to access the products within the selected category.
Just follow these simple steps:
- Go to Products > Categories in wp-admin
- Open a category you want to restrict.
Now select the following values to restrict this category for users who haven’t purchased a specific product:
- Enable the conditional restrictions: Yes
- Apply restrictions to: Category and posts
- What happens when the conditions are met: Allow access
- Condition 1: User has purchased product = Product
- You select the product you want to set as a prerequisite to purchasing this product.
- To add more products, click + to add a new condition to the same group.
- To add another product as an option, click Add ‘Or’ group and select the condition.
- Update the product to save the changes.
Now the users who haven’t purchased the selected product won’t be able to purchase the products within the selected category.
What if users haven’t purchased the selected products and want to access the restricted products?
Here’s how you can select what happens when users haven’t purchased the selected products and want to access the restricted products:
- Go to Settings > Post restrictions.
Once there, you’ll see these fields and options:
- Enable restrictions: Tick/untick this checkbox to enable/disable the global conditions.
- Don’t apply restrictions for these user roles: You’ll see a list of user roles for which the conditions won’t be applied. By default, we will not apply restrictions for administrators, editors, and any user with the capability edit_others_posts.
- What happens when the post is restricted? You have several options to select what happens when the post is restricted:
- Redirect to URL
- Remove the content and show a message
- Show fragment of the content and show message after fragment
- What happens when a category is restricted? You have several options to select what happens when the post is restricted:
- Show error 404
- Show the normal page without posts
- Show an error message
- Redirect to another URL
- Show the content of another page
Once you select the global settings, just save the changes.
That was really simple!
As you can see, it’s really simple to restrict WooCommerce products based on a previously purchased product. You don’t have to program anything nor hire programmers. You can easily apply this and any other conditional restrictions to your posts, pages, products, and any other custom post type generated by other WordPress plugins.
You can download the plugin here:
Download WordPress Conditional Post Restrictions Plugin - or - Read more