There is a default option in WooCommerce that lets you redirect users directly to the cart when they’ve added a new product to their cart. If you want to redirect users to lets say a landings page, you can do that by adding a small code snippet.

Redirect users to cart after add to cart

This is the default option that is build into WooCommerce. You can find the option in the WooCommerce -> Settings -> Products -> Display area. When the option “Redirect to the cart page after successful addition” is checked it will redirect all users to the cart after adding a product to the cart.


Redirect users to a custom page

To redirect users to a different page page you can use the following code snippet. This will redirect the users to the page with ID 1. You can also set a fully custom URL, or build a URL of the current site with home_url( 'services/' );.

Redirect to checkout after add to cart

A other common scenario is redirecting the user to the checkout when they’ve added a product to their cart. This may come in handy if you only sell one product / one product per time.

Conditionally redirect users after add to cart

Maybe you want to redirect users to a different page only when they add a specific product to the cart or a product from a specific category/shipping class. The following code snippets give some examples in those scenarios.

Important! In order for the conditional redirects to work correctly you will need to disable the AJAX add to cart buttons.

You can disable the AJAX add to cart buttons on the same settings page as illustrated above by unchecking the option “Enable AJAX add to cart buttons on archives”.

Redirect for certain products

Redirect for certain categories

Redirect for certain shipping classes

Update: WooCommerce Add to Cart Redirect plugin

I’ve created a plugin that allows for setting up the redirect after add to cart directly within the plugin settings.

Purchase the WooCommerce Add to Cart Redirect plugin.

Jeroen Sormani

I'm a professional WordPress plugin developer on a mission to create the best plugins for my clients. I'm specialised in developing general WordPress, WooCommerce and Easy Digital Downloads plugins.

Interested in talking about a WordPress project? Get in touch!

Follow me on Twitter

76 thoughts on “Redirect users after add to cart

Christopher West January 14, 2021 at 4:09 am

I meant 341 is the variation (342 is another variation)

Jack January 31, 2021 at 12:38 am

A potentially noob question- where exactly do we paste these wonderful code snippets?

Jeroen Sormani January 31, 2021 at 11:52 am
Rubb February 3, 2021 at 1:21 pm

Great post, is there option to redirect users to the pervious page?
I using “” to add product and want the users to return to the pervious page they was before adding and show message they know the product was added.
Different question can I do this with the “return to shop” button on the cart? I want the user return to the pervious page

Jeroen Sormani February 3, 2021 at 1:39 pm

Hi Rubb,

This can be done, you can use one of the paremeters of the $_SERVER global for this to find the previous page.
Not sure what you mean with the second part.


Martin Hinrichsen March 11, 2021 at 2:21 pm

I cannot get “Redirect for certain products” to work.
Has something changed in woocommerce?
It seems to be impossible to get the ID of the product to trigger the Conditional redirect URL.

Jeroen Sormani March 18, 2021 at 2:18 pm

Hi Martin,

It should all still work, nothing has changed in Woo. Maybe there’s something else that overrides the snippet.


Jake R June 10, 2021 at 10:51 pm

Can these work with Ajax enabled? Just have a few products that I want to redirect and don’t want to turn off Ajax for the rest. Thanks for any input

Jeroen Sormani June 11, 2021 at 10:46 am

Hi Jake,

It is possible to do this, but requires a different code than what is available here (this is server side code, that would be JavaScript for front-end).
AJAX redirects are available in the WooCommerce Add to Cart Redirect plugin if you want to use that.


Nellie July 11, 2021 at 1:47 am

Not sure if this helps anyone, but based on the above codes (thanks, Jeroen!) I created the below code that redirects to the cart ONLY when clicking from a certain page:

* Redirect users after add to cart.
function my_custom_add_to_cart_redirect( $url ) {

if ( is_page( ‘1’ )) {
$url = get_permalink( ‘1’ ); // URL to redirect to (1 is the page ID here)

return $url;

add_filter( ‘woocommerce_add_to_cart_redirect’, ‘my_custom_add_to_cart_redirect’ );

I’m certainly not a PHP coder and simply played with copy-pasting to get the above working (so if it would need improvements, let me know ๐Ÿ™‚ )

marc October 2, 2021 at 8:53 am

You just saved my life! I was trying to redirect users to a different page after adding products from a specific category, such as to create a step-by-step guided shopping experience.

Your code to redirect for certain categories worked like charm

thank you!

Leave a Reply