How to Disable Ajax Add to Cart on Product page in Magento 2
Happy New Year Readers! 🥳 Let’s make a good start of the new year with a new Magento solution! 📖
Do your large number of customers abandon cart due to lengthy checkout process? Do you want to optimize the checkout process so that you never lose a chunk of users who could have been your potential customers?!
The default behavior of the Magento 2 “Add to Cart” button is on click, it uses an ajax to add the product to cart and keep the user on the product page.
Now, in order to boost the order process, you need to disable ajax add to cart on the product page in Magento 2 and redirect customers directly to the checkout page. This can help push your customers for the purchase and also save your customers’ time for completing the order.
Steps to Disable Ajax Add to Cart on Product Page in Magento 2:
- Find the following code from vendor\magento\module-catalog\view\frontend\templates\product\view\addtocart.phtml file
123456789<script type="text/x-magento-init">   {     "#product_addtocart_form": {      "Magento_Catalog/product/view/validation": {        "radioCheckboxClosest": ".nested"       }     }   }</script> - Go to app/design/frontend/[Vendor]/[Theme]/Magento_Catalog/templates/product/view/addtocart.phtml and replace the below code to add the bindsubmit event:
12345678910<script type="text/x-magento-init">  {   "#product_addtocart_form": {    "Magento_Catalog/product/view/validation": {       "bindSubmit": true,       "radioCheckboxClosest": ".nested"     }   }  }</script> - To Redirect customers from cart page to the checkout page cart on click of add to cart button, Go to Stores > Configuration > Sales > Checkout > Shopping Cart and set “After Adding a Product Redirect to Shopping Cart” to Yes.
That’s all to disable ajax add to cart on Magento 2 product page and redirect customers directly to the checkout page.
Don’t forget to comment down your issues or queries in the comment section below, I would be happy to help 🙂
If you like the solution, don’t forget to share it with your Magento buddies!
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
Meetanshi Magento Extensions Launches and Updates December [2019]
Solved: Magento 2 Product URLs Double html Suffix Problem
Next