WooCommerce : When adding product to cart and then refreshing the page it adds product again to cart.

Code

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 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.

This is because when add to cart process is not executed using ajax , than it is executed by query string.

When Adding product to cart using query string, URL becomes something like this”?add-to-cart=1234&quantity=1” 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.

There is a option in WooCommerce that lets you redirect customers directly to the cart when they’ve 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.

For This You can use 'woocommerce_add_to_cart_redirect' hook.

function CustomAddToCartRedirect() {
  $url = WC()->cart->get_checkout_url();
  return $url;
}
add_filter(‘woocommerce_add_to_cart_redirect’,‘CustomAddToCartRedirect’ );

If You want redirecting user to same page you can do that by adding a small code to functions.php.

function CustomAddToCartRedirect() {
  $url=”//”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
  return $url;
}
add_filter(‘woocommerce_add_to_cart_redirect’,‘CustomAddToCartRedirect’ );

If You want redirecting user to Any Other Custum page you can do that by adding a small code to functions.php.

function CustomAddToCartRedirect() {
  $url = get_permalink(123); // 123 is the page ID here
  return $url;
}
add_filter(‘woocommerce_add_to_cart_redirect’,‘CustomAddToCartRedirect’ );

Enjoy

Related reading:

Shiv Kumawat

Executive Director & CEO

Shiv Kumawat is the CEO of Eoxys IT Solution LLP, the Jaipur-based IT company he has led since 2009. An AI & IT Solutions Consultant with 16+ years of experience, he works with startups and enterprises to turn ideas into market-ready SaaS platforms, mobile apps and AI-driven solutions. His team has delivered 700+ projects across SaaS, mobile and web apps, automation and AI. He previously served as Chief Technology Officer for a US company.

Latest Posts

Isometric illustration of an AI voice agent: a smartphone with a sound wave linked to a headset robot receptionist, a booking calendar and stacks of coins

AI Voice Agent Cost in 2026: Platforms vs a Custom Build

A missed call at a clinic, salon or service business is often a missed booking. That is why owners now…

Shafeeq Khan
October 22, 2026
Isometric illustration of an AI answer panel citing a business website, with an AI crawler and search pages connected to it, for an AEO services guide

AEO Services: Get Cited in ChatGPT and Google AI Overviews

When a buyer asks ChatGPT, Perplexity, Gemini or Google’s AI Overviews “who builds X in India?” or “what does Y…

Shafeeq Khan
October 19, 2026
Isometric illustration of an old AI model chip being swapped for a new one in a server that powers web and mobile apps, for a GPT-4o API migration guide

GPT-4o API Shutdown: Migrate Your App Before 14 January 2027

If your chatbot, document pipeline or internal tool still calls GPT-4o or GPT-4.1, it has a deadline. On 14 October…

Shafeeq Khan
October 19, 2026
,

Leave a Reply

Your email address will not be published. Required fields are marked *