{"id":7263,"date":"2020-05-16T03:41:07","date_gmt":"2020-05-16T03:41:07","guid":{"rendered":"https:\/\/expertwebtechnologies.com\/?p=7263"},"modified":"2025-01-07T13:39:23","modified_gmt":"2025-01-07T13:39:23","slug":"woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart","status":"publish","type":"post","link":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/","title":{"rendered":"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart."},"content":{"rendered":"\n<div>\n<h1>WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart.<\/h1>\n<h3>Add to cart duplicates products on refresh page?<\/h3>\n<p>Generally in WooCommerce clicking on Add-to-Cart and it successfully add the product and display the message that the product is added. And on refreshing the page and message did not disappear and it adds the product once more to cart. And how many times am refreshing the page it is adding the product again to cart.<\/p>\n<p>This is because when add to cart process is not executed using ajax , than it is executed by query string.<\/p>\n<p>When Adding product to cart using query string, URL becomes something like this&#8221;?add-to-cart=1234&amp;quantity=1\u201d so when we refresh the page, this will again execute and product will again add to cart. So to Remove This Issue We have To redirect the page after add to cart.<\/p>\n<p>There is a option in WooCommerce that lets you redirect customers directly to the cart when they\u2019ve added a new product to their cart. If you want to redirect customers to lets say a checkout page, you can do that by adding a small code to functions.php.<\/p>\n<p>For This You can use <code style=\"color: seagreen;\">'woocommerce_add_to_cart_redirect'<\/code> hook.<\/p>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"snip keyword\">function<\/span> <span class=\"snip function\">CustomAddToCartRedirect<\/span>() {\n&nbsp;&nbsp;$url = <span class=\"snip function\">WC<\/span>()-&gt;cart-&gt;<span class=\"snip function\">get_checkout_url<\/span>();\n&nbsp;&nbsp;<span class=\"snip keyword\">return<\/span> $url;\n}\n<span class=\"snip function\">add_filter<\/span>(<span class=\"snip string\">\u2018woocommerce_add_to_cart_redirect\u2019<\/span>,<span class=\"snip string\">\u2018CustomAddToCartRedirect\u2019<\/span> );\n<\/code><\/pre>\n<p>If You want redirecting user to same page you can do that by adding a small code to functions.php.<\/p>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"snip keyword\">function<\/span> <span class=\"snip function\">CustomAddToCartRedirect<\/span>() {\n&nbsp;&nbsp;$url=\u201d\/\/\u201d.$_SERVER[\u2018HTTP_HOST\u2019].$_SERVER[\u2018REQUEST_URI\u2019];\n&nbsp;&nbsp;<span class=\"snip keyword\">return<\/span> $url;\n}\n<span class=\"snip function\">add_filter<\/span>(<span class=\"snip string\">\u2018woocommerce_add_to_cart_redirect\u2019<\/span>,<span class=\"snip string\">\u2018CustomAddToCartRedirect\u2019<\/span> );\n<\/code><\/pre>\n<p>If You want redirecting user to Any Other Custum page you can do that by adding a small code to functions.php.<\/p>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"snip keyword\">function<\/span> <span class=\"snip function\">CustomAddToCartRedirect<\/span>() {\n&nbsp;&nbsp;$url = <span class=\"snip function\">get_permalink<\/span>(123); \/\/ 123 is the page ID here\n&nbsp;&nbsp;<span class=\"snip keyword\">return<\/span> $url;\n}\n<span class=\"snip function\">add_filter<\/span>(<span class=\"snip string\">\u2018woocommerce_add_to_cart_redirect\u2019<\/span>,<span class=\"snip string\">\u2018CustomAddToCartRedirect\u2019<\/span> );\n<\/code><\/pre>\n<p>Enjoy<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. Add to cart duplicates products on refresh page? Generally in WooCommerce clicking on Add-to-Cart and it successfully add the product and display the message that the product is added. And on refreshing the page and message did [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8674,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,35,36],"tags":[],"class_list":["post-7263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocommerce","category-woocommerce-hooks","category-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. - EoXys IT<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. - EoXys IT\" \/>\n<meta property=\"og:description\" content=\"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. Add to cart duplicates products on refresh page? Generally in WooCommerce clicking on Add-to-Cart and it successfully add the product and display the message that the product is added. And on refreshing the page and message did [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/\" \/>\n<meta property=\"og:site_name\" content=\"EoXys IT\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-16T03:41:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-07T13:39:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png\" \/>\n\t<meta property=\"og:image:width\" content=\"768\" \/>\n\t<meta property=\"og:image:height\" content=\"430\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Shiv kumawat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shiv kumawat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/\"},\"author\":{\"name\":\"Shiv kumawat\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e\"},\"headline\":\"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart.\",\"datePublished\":\"2020-05-16T03:41:07+00:00\",\"dateModified\":\"2025-01-07T13:39:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/\"},\"wordCount\":264,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png\",\"articleSection\":[\"Woocommerce\",\"Woocommerce Hooks\",\"WordPress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/\",\"url\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/\",\"name\":\"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. - EoXys IT\",\"isPartOf\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png\",\"datePublished\":\"2020-05-16T03:41:07+00:00\",\"dateModified\":\"2025-01-07T13:39:23+00:00\",\"author\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e\"},\"breadcrumb\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#primaryimage\",\"url\":\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png\",\"contentUrl\":\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png\",\"width\":768,\"height\":430,\"caption\":\"Code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eoxysit.com\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/#website\",\"url\":\"https:\/\/eoxysit.com\/blogs\/\",\"name\":\"EoXys IT\",\"description\":\"Digitise your business\",\"alternateName\":\"Eoxys It\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eoxysit.com\/blogs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e\",\"name\":\"Shiv kumawat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2025\/03\/CEO-150x150.png\",\"contentUrl\":\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2025\/03\/CEO-150x150.png\",\"caption\":\"Shiv kumawat\"},\"description\":\"\\\"Shiv kumawat is the Executive Director and CEO of Eoxys It Solution LLP and the strategic mind behind the company\\\"s growth. His expertise in operational efficiency and team leadership empowers his colleagues to excel and innovate.\u201d\",\"sameAs\":[\"https:\/\/eoxysit.com\/\"],\"url\":\"https:\/\/eoxysit.com\/blogs\/author\/shivkumawat1985\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. - EoXys IT","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/","og_locale":"en_US","og_type":"article","og_title":"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. - EoXys IT","og_description":"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. Add to cart duplicates products on refresh page? Generally in WooCommerce clicking on Add-to-Cart and it successfully add the product and display the message that the product is added. And on refreshing the page and message did [&hellip;]","og_url":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/","og_site_name":"EoXys IT","article_published_time":"2020-05-16T03:41:07+00:00","article_modified_time":"2025-01-07T13:39:23+00:00","og_image":[{"width":768,"height":430,"url":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png","type":"image\/png"}],"author":"Shiv kumawat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Shiv kumawat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#article","isPartOf":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/"},"author":{"name":"Shiv kumawat","@id":"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e"},"headline":"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart.","datePublished":"2020-05-16T03:41:07+00:00","dateModified":"2025-01-07T13:39:23+00:00","mainEntityOfPage":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/"},"wordCount":264,"commentCount":0,"image":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#primaryimage"},"thumbnailUrl":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png","articleSection":["Woocommerce","Woocommerce Hooks","WordPress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/","url":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/","name":"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart. - EoXys IT","isPartOf":{"@id":"https:\/\/eoxysit.com\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#primaryimage"},"image":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#primaryimage"},"thumbnailUrl":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png","datePublished":"2020-05-16T03:41:07+00:00","dateModified":"2025-01-07T13:39:23+00:00","author":{"@id":"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e"},"breadcrumb":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#primaryimage","url":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png","contentUrl":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2021\/06\/woocommerce-products-custom-fields.png","width":768,"height":430,"caption":"Code"},{"@type":"BreadcrumbList","@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-when-adding-product-to-cart-and-then-refreshing-the-page-it-adds-product-again-to-cart\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eoxysit.com\/blogs\/"},{"@type":"ListItem","position":2,"name":"WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart."}]},{"@type":"WebSite","@id":"https:\/\/eoxysit.com\/blogs\/#website","url":"https:\/\/eoxysit.com\/blogs\/","name":"EoXys IT","description":"Digitise your business","alternateName":"Eoxys It","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eoxysit.com\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e","name":"Shiv kumawat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2025\/03\/CEO-150x150.png","contentUrl":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2025\/03\/CEO-150x150.png","caption":"Shiv kumawat"},"description":"\"Shiv kumawat is the Executive Director and CEO of Eoxys It Solution LLP and the strategic mind behind the company\"s growth. His expertise in operational efficiency and team leadership empowers his colleagues to excel and innovate.\u201d","sameAs":["https:\/\/eoxysit.com\/"],"url":"https:\/\/eoxysit.com\/blogs\/author\/shivkumawat1985\/"}]}},"_links":{"self":[{"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/posts\/7263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/comments?post=7263"}],"version-history":[{"count":0,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/posts\/7263\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/media\/8674"}],"wp:attachment":[{"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/media?parent=7263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/categories?post=7263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/tags?post=7263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}