Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Commerce Product Restriction

Security covered Under active development 19 sites

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

  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.

Drupal 8–10 · not 11

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

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Nov 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
1.1.0 Stable 8–10 Nov 6, 2023
1.0.0 Stable 8–9 Nov 6, 2023