Solved: Magento 2 Add to Cart Button Not Working
Its been almost two years now since Magento 2 has been released, and it’s getting better with each day due to the contributions from the developers all over the world. However, there are certain issues you may face while working with Magento 2. One of them is “Magento 2 Add to Cart button not working“.
There are many reasons for add to cart not working or stopped working. Some of them are infinite redirection loop, 3rd party extension conflicts, form_key mismatch etc.
Magento 2 Add to Cart button not working on Home page
Most of the time, the issue arises due to change in custom theme, adding custom CSS, adding products to cart from home page and refreshing the page doesn’t add the product to cart.
Such a situation arises when there’s something wrong in the cache.
Follow the below steps to solve the issue:
- Login to Magento 2 backend.
- Go to System > Cache Management and select all of the caching options built in your Magento 2.
- In the drop-down, select Enable and then click on Submit.
And you’re done!
Magento 2 Add to Cart button not working on the Categories and Product Page
When a user adds a product to cart from categories or product page, he/she is redirected to the checkout page with an empty cart. This happens because of the domain change as Magento 2 stores root URL in the third path without affecting the first version.
To resolve the issue, you need to run additional SQL query:
1 2 3 |
UPDATE core_config_data SET value = REPLACE(value, '<old root URL or domain>', '<new root URL or domain>') WHERE path = 'design/head/includes'; |
Moreover, delete the cache using the following command:
1 |
rm -rf var/cache/* |
Now that you have the solution, don’t let such small issues stop your live Magento 2 store work well. ?
Please mention your doubts in the comment section to help you out if you stuck somewhere. Also, let me know where have you used this solution and what arises this issue!
Rate the blog post with 5 stars if you liked it.
Happy Coding!
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.
2 Comments
Hi Sanjay,
I have problem on my store that add to cart button is not working on the product page. But it is working on the homepage.
Nothing happens on product page when I hit add to cart button. There is no error showing in the console and nothing happens.
Surprised what is going on and confused what is the reason behind this.
Please help immediately.
Thanks and Regards,
Kamal
Hello Kamal,
Please contact us for your custom requirements if you want to avail professional help of our certified Magento developers.
Your issue requires customization which is out of the scope of the above blog’s solution.
Thank you.