Hi guys,
i have a condition. if that condition success then only the product should added to the cart.I have a condition but i want to know where exactly i should place that condition. I need files to add that condition .
can any one help me ?
Solved! Go to Solution.
For add custom conditions before the add To cart in Magento 2, You need to find the line with $block->getAddToCartUrl from Catalog module templates.
getAddToCartUrl() function is responsible for fetch add action of cart.
Many files contain the line as above defined, which is responsible for add to cart in the store. So you need to override specific file and before above action, you need to set your custom conditions.
By default all the products in Magento 2 before add, They perform action Add Controller in Checkout module.
You can check file, vendor/magento/module-checkout/Controller/Cart/Add.php
You need to Override controller file in your custom module or you can create plugin for execute() method of Add.php file for setting your custom conditions.
But i want to put that condition in .phtml file. Can you guide me ?
how can i acheive it ?
For add custom conditions before the add To cart in Magento 2, You need to find the line with $block->getAddToCartUrl from Catalog module templates.
getAddToCartUrl() function is responsible for fetch add action of cart.
Many files contain the line as above defined, which is responsible for add to cart in the store. So you need to override specific file and before above action, you need to set your custom conditions.