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

  1. Install and enable the module
  2. To a product type or product variation type, add a field of type Plugin -> Product restriction
  3. Important! In the "Manage form display", make sure the field has "Product restrictions" set as the widget.
  4. 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.

Supporting organizations: 
Primary developer

Project information

Releases