We need the condition to trigger only if the cart items match the categories listed and there are no products that do not match.

Is there a way to limit Commerce Shipping Method Conditions (Product->Order Contains Product Categories) to trigger only if the order products match the categories and there none that do not match?

enter image description here

1 Answer 1


Unfortunately, the way that condition was written, it only matches for, "Order contains any products from these categories." The logic you're looking for is, "Order contains only products from these categories." For that, you'd need to write a custom condition plugin. This would be a reasonable core feature request for Drupal Commerce and would apply for the other "contains" conditions as well ... which leads me to believe we might implement it as an "operator" select list on the condition itself.

  • Thank you Ryan. Yep, I already created the custom condition. It was quite easy, using the core 'order contains categories' condition and modifying. Aug 25, 2020 at 12:33
  • @quantumized Oh, nice! Congrats on figuring that out. Does it seem like something you'd want to use to kick off a core feature request that we apply to each of those Order condition types? Aug 26, 2020 at 14:15
  • yes, I think it would be a useful feature to have. What do I need to do to 'kick off a core feature request'? Just submit a require in the issue queue? Should I submit a patch with the code too? Aug 27, 2020 at 14:36
  • @quantumized Yep! Just open the issue in drupal.org/project/issues/commerce and feel free to link back to this discussion. A patch as a starting point would be great! Aug 31, 2020 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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