Is there a way to limit users on my site to buy only 2 items from a list of products? Am using Drupal 7 with Commerce module and Rules. I added a new rule to when adding or removing and item from the shopping cart, it would check if the total quantity is bigger than 2, then it would remove the last element like this.

Event Before adding a product to the cart

After adding a product to the cart


Total product quantity comparison Parameter: Order: [commerce_order], Operator: >, Quantity: 2


Remove an item from a list

Selected list: commerce-order:commerce-line-items

and the item to remove is


Sadly its not working, and I really need your help. thanks

  • The conversation at drupalcommerce.org/node/673 may be useful to you, but you have more sophisticated requirements.
    – rfay
    Sep 21, 2011 at 13:59
  • well, this is helpful but in my case cause I want the action to be removing an element from the cart.
    – saadlulu
    Sep 21, 2011 at 14:46
  • stumbled on this, but if you are still looking for the rule(s) necessary to limit product quantities, you can see the post at <a href="drupalcommerce.org/node/1053">http://…>
    – Will
    Nov 28, 2011 at 11:47

1 Answer 1


I had a similar problem: I had to check for certain conditions before adding an item to the cart (not after adding). And if the condition is not met the item should not be added.

The only way i could resolve this is by adding a "Execute custom PHP code" action with the code:


This doesn't look very correct but its the only thing that worked for me.

  • 1
    this doesn't seem to be very robust solution :) but it may came in handy
    – saadlulu
    Nov 28, 2011 at 12:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.