In Magento 2, you may face the issue of Add To Cart button not working all of a sudden for some reason. This post will guide you how to fix some of the most common ones.
Add to Cart not working from homepage
It’s actually very simple to fix this issue:
- Login to your Magento 2 backend.
- Navigate to System > Cache Management and choose all of the caching options built in your Magento 2.
- In the dropdown, choose Enable and then click on Submit.
Add to Cart not working from categories and products page
Since Magento 2 stores root URL in the third path (e.g.: design/head/includes), the problem usually occurs after a domain change. Follow 2 below steps and you will be good to go.
- Run the additional SQL lines below
UPDATE core_config_data SET value = REPLACE(value, '<old root URL or domain>', '<new root URL or domain>') WHERE path = 'design/head/includes';
- Delete the cache with the command:
rm -rf var/cache/*
Add to Cart button stuck at Adding
If you’re running Magento on a local environment and using the default http://localhost/ as base URL, it’s possible that your base URL is the issue. To get around this, you’ll need to change your base URL to http://127.0.0.1/ as this way guarantees better compatibility.
To do this, you’ll need to access your database and find the
In this table you’ll want to pay attention to these two rows:
Now change only
127.0.0.1 and keep everything else the same. For example, if your base URL is
http://localhost/magento24, you’ll need to change it to
After you’re done changing your base URL, don’t forget to flush your cache using:
php bin/magento cache:flush