How to Set Conditions to Restrict Adding Products in Magento 2

Product management becomes tricky when you want to sell products with the conditions. Some of the examples are allowing to add only one product in the cart, adding only one product from each category, only adding one product type in the cart, no two products can be added with each other and many other rules. To apply such rules, you have to Set Conditions to Restrict Adding Products in Magento 2 and work on cart conditions and events.

Here, I’ve come up with the custom code to set conditions to restrict adding Magento 2 products to the shopping cart. The only thing you have to do is define the condition as per your requirement.

Steps to Set Conditions to Restrict Adding Products in Magento 2:

  1. Create event.xml in etc folder
  2. Create Cartadd.php file under the Observer folder

With the above method, you can control inventory and set conditions to restrict adding Magento 2 products by the users in the front end!

Or, you could simply use the Magento 2 Call for Price extension to restrict customers to add products to the cart and instead call you for inquiring about pricing. The extension will hide the product prices and the “Add to Cart” button.

Let me know your doubts and questions in the comments section. Also, let me know how this code has helped and which conditions you have set to restrict adding Magento 2 products.

Don’t forget to rate the post with 5 stars!

Thanks 🙂

5
(based on 7 Reviews)
How to Set Conditions to Restrict Adding Products in Magento 2Author Magento Badge

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply

Your email address will not be published.