{"id":117,"date":"2018-06-12T07:43:14","date_gmt":"2018-06-12T07:43:14","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/06\/12\/magento-2-add-to-cart-button-not-working\/"},"modified":"2025-07-17T17:05:08","modified_gmt":"2025-07-17T11:35:08","slug":"magento-2-add-to-cart-button-not-working","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-add-to-cart-button-not-working\/","title":{"rendered":"Solved: Magento 2 Add to Cart Button Not Working"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Its been almost two years now since Magento 2 has been released, and it\u2019s 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 \u201c<em><strong>Magento 2<\/strong><\/em>&nbsp;<em><strong>Add to Cart button not working<\/strong><\/em>\u201c.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Magento 2 Add to Cart button not working on Home page<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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\u2019t add the product to cart.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Such a situation arises when there\u2019s something wrong in the cache.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the below steps to solve the issue:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Login to Magento 2 backend.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Go to&nbsp;<strong>System &gt; Cache Management<\/strong>&nbsp;and select all of the caching options built in your Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. In the drop-down, select&nbsp;<strong>Enable&nbsp;<\/strong>and then click on&nbsp;<strong>Submit<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2018\/06\/enabling-cache-1024x668.png\" alt=\"enabling cache types\" class=\"wp-image-3097\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And you\u2019re done!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Magento 2 Add to Cart button not working on the Categories and Product Page<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To resolve the issue, you need to run additional SQL query:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">UPDATE core_config_data\nSET value = REPLACE(value, '&lt;old root URL or domain>', '&lt;new root URL or domain>')\nWHERE path = 'design\/head\/includes';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Moreover, delete the cache using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -rf var\/cache\/*<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you have the solution, don\u2019t let such small issues stop your live Magento 2 store work well.&nbsp;?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy Coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Its been almost two years now since Magento 2 has been released, and it\u2019s getting better with each day due to the contributions from the&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":14022,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/117\/revisions\/14022"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}