Part of the Commerce ecosystem · 497 projects
This module restricts product purchases by disabling the add to cart button and displaying a message when certain conditions are met. These conditions, which can be set at the product or product variation level, include specific date periods, password protection, user roles, or individual users. It also supports restricting the total quantity of a product a user can purchase across all their orders.
This module allows restricting the purchase of products for customers, disabling purchase at the point of adding to cart and displaying a message in place of the add to cart button.
A field referencing these restrictions can be added to any product type or product variation type, and when the product or product variation is edited users can specify which conditions apply to purchase.
Restrictions can be applied on the product level or product variation level, or both. In future it may be possible to apply them for product types and product variation types as well.
Important note
in the short term the restrictions apply only at the add to cart step. This means using "add to cart link" etc may not protect purchases. This is due to the AvailabilityChecker functionality in commerce seeming not to maintain the current user, and instead running some checks as the anonymous user.
Included restriction plugins
Restrict purchase to:
- A specific date period
- Password protected
- Restrict purchase quantity across all user's orders
- Users with specified user roles
- Specific users
To install
- Install and enable the module
- To a product type or product variation type, add a field of type Plugin -> Product restriction
- Important! In the "Manage form display", make sure the field has "Product restrictions" set as the widget.
- Edit a product or variation of that type to add restrictions.
Custom restriction plugins
This module creates a new ProductRestrictionPlugin type, which extends the existing Commerce Condition plugin type. You just need to create a @ProductRestrictionPlugin under Plugin/Commerce/ProductRestriction in which you:
- specify an "evaluate" function to determine whether the user has access
- provide a settings form to provide detail for the conditions
- optionally specify an error message function
See the included plugins for examples.
Ask your assistant about Commerce Product Restriction
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
- Commerce Core
- Commerce Core commerce_cart
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the Commerce ecosystem
Most installed first