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

75 thoughts on “Redirect users after add to cart

Alex December 6, 2015 at 4:20 pm

Hi Jeroen,

i do like this functions, very good. I am using them myself. I just didn’t get the hang of to disable the class when someone clicks the add to cart. (I don’t want the product to be added to cart, because i only showcase the products online, people can’t buy it, unless they come into the shop)

So what i have done is:

This does let me change the text of the Add to cart:

add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’ ); // 2.1 +

function woo_custom_cart_button_text() {

return __( ‘Contact Us’, ‘woocommerce’ );


This does redirect me to my contact page instead of add to cart:
function custom_add_to_cart_redirect() {
return get_permalink( 8 ); // Replace the 123 with your page ID!

Do you maybe know the snippet that i can add to my functions.php, so the product doesn’t get added to cart?

I tried:

/* remove add to cart class */
add_filter(‘add_to_cart_class’, ‘woo_custom_cart_button_class’);
function woo_custom_cart_button_class() {
return __(‘more_info_button’, ‘woocommerce’);

Unfortunate that didn’t work, i guess that is only for old WC versions.

Thank you and have a nice day

jeroen December 7, 2015 at 7:17 pm

Hi Alex,

I don’t have a code snippet available to prevent adding a product to the cart..
Have you tried setting the product to not-in-stock?


Alex December 9, 2015 at 11:23 pm

Hi again,

I did find a way to hide the add to cart message with css. But thats not bulletproof. I don’t like css much. I prefer php as people can’t change that. So when you ever find a way to prevent add to cart, show it to the people. thanks!


Shaun January 28, 2017 at 9:38 pm

Hey i did not see where you mention where to insert the code snippets in the theme or the plugin? can you please specify where the snippets should go thank man! cheers!

Jeroen January 29, 2017 at 10:50 am

Hi Shaun,

Take a look at this post on how to add code snippets:


John February 12, 2016 at 12:49 pm

What if we want to redirect to product page after clicking on add to cart button?

John February 12, 2016 at 12:54 pm

Solved with this code

function my_custom_add_to_cart_redirect( $url ) {
if ( ! isset( $_REQUEST[‘add-to-cart’] ) || ! is_numeric( $_REQUEST[‘add-to-cart’] ) ) {
return $url;
$product_id = apply_filters( ‘woocommerce_add_to_cart_product_id’, absint( $_REQUEST[‘add-to-cart’] ) );
// Only redirect products with the ‘small-item’ shipping class
$url = get_permalink( $product_id );
return $url;
add_filter( ‘woocommerce_add_to_cart_redirect’, ‘my_custom_add_to_cart_redirect’ );

jeroen February 13, 2016 at 11:10 am

Glad you already found the solution John, thanks for sharing!

Florian March 20, 2016 at 12:35 pm

Hi Jeroen!

I tried to redirect certain products but I can’t manage to get it work and its really annoying, I don’t know what Im doing wrong. I took your code:


return $url;
add_filter( ‘woocommerce_add_to_cart_redirect’, ‘my_custom_add_to_cart_redirect’ );

And replaced the product IDs but nothing happens, It only redirects me to the cart and not the checkout.. Please help me!

Best regards

Florian March 20, 2016 at 12:36 pm

Sorry I mean this code snippet..

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

if ( ! isset( $_REQUEST[‘add-to-cart’] ) || ! is_numeric( $_REQUEST[‘add-to-cart’] ) ) {
return $url;

$product_id = apply_filters( ‘woocommerce_add_to_cart_product_id’, absint( $_REQUEST[‘add-to-cart’] ) );

// Only redirect the product IDs in the array to the checkout
if ( in_array( $product_id, array( 1, 16, 24) ) ) {
$url = WC()->cart->get_checkout_url();

return $url;
add_filter( ‘woocommerce_add_to_cart_redirect’, ‘my_custom_add_to_cart_redirect’ );

jeroen March 21, 2016 at 6:51 pm

Hi Florian,

Hard to say what the reason is.. You’d probably have to do some debugging.
As a test, this is the most minimal version:


Akeem March 22, 2016 at 8:53 pm

thanks for this! you are awesome!

Abaz April 2, 2016 at 9:22 am

Hi Jeroen!
I have a website with amazon affiliate programs and i am using woocommerce. When i try to push the button ”ad to cart” then it takes me to cart page and when i push the checkout button it doesn’t redirect me to the amazon product page. Can you help me solve this problem? My website is

m May 26, 2016 at 6:44 pm

Hi Jeroen,
It is surely obvious for you, but i am new to all this… In the code snippet hereafter:

{snippet removed to keep things clear πŸ˜‰ ~Jeroen}

It is clear to me that I have to insert product ID in the array but please tell me where should i insert the page ID (url) i want to redirect to…

Thank you so much!

jeroen May 26, 2016 at 8:03 pm


You can do that at the `$url = ”;` part the line below that array.


Clint June 2, 2016 at 10:00 am

Hey Jeroen, these are great !

We’ve been looking for something similar to these (skip cart and redirect straight to checkout), but it’s a bit different. Maybe you can add this function to your list if you can help us with it, it may be a challenge because it’s puzzling us.

We’re using a custom worpdress page template and we’re using a custom url on that page template that will automatically add the item to the cart when clicked.

So for example, I’ve got: landing-page.php
the add product to cart link on this page:

Whenever I use this template, the product link I put on it should skip the cart page and redirect straight to checkout. *This function should only work on this template, every other product page should operate normally.

Do you thnk this is possible? We appreciate the help in advance if you decide to give this a shot!

jeroen June 2, 2016 at 7:45 pm

Hi Clint,

Although I think its possible to do a conditional check for page template, maybe there’s a easier solution possible..
As you’re mentioning a custom page template, how are the products added to it (more specifically the add to cart link)? Also in a custom way?

If so, you could add a additional parameter to the URL, e.g. &redirect-checkout=1.

Otherwise, you can add a conditional check using the is_page_template( 'template_slug' ) function.

Hope that helps πŸ™‚


Vishal Kakadiya July 13, 2016 at 12:16 pm

Hi Jeroen,

Thanks for this article…
Great article! Find all the details at one place

Thanks you so much πŸ™‚

Billy R. July 30, 2016 at 12:44 am

Dude! Thank you! This is exactly what I needed. I don’t know why WooCommerce didn’t think to include this kind of functionality on a per product or per category basis out of the box.

Either way, thank you again! Works perfectly πŸ™‚

skanda September 22, 2016 at 2:25 pm


Thank you.

Angelo November 22, 2016 at 11:08 am

Hi, thanks for the great article… but, i have a question: if i would like to remove completely the redirect ?

I mean… if you go here:

after you press the 5 Kg button, woocommerce will correctly add the product and than you will redirect to the site home…i would like to stay on my test-2 pages… do you think it’s possible?

Thank you very much

Jeroen November 22, 2016 at 2:22 pm

Hi Angelo,

WooCommerce shouldn’t redirect you to the home at all. If you don’t want to redirect the user you shouldn’t either add a code snippet from here either.

It could be there is something not setup correctly in regards of say your permalinks, but thats not something I would be able to help you out with from here.

Hope that helps!


Harsh Kumar November 22, 2016 at 11:49 pm

Hi Jeroen,

Is there a way I can redirect the “Add to cart” button to a custom URL based on the specific ID of the product, i.e. if a product with ID = 45 is clicked the button redirects to a custom URL and if a ‘Add to cart’ link for the product with ID = 46 is clicked, the button redirects to a different URL and same for the product with variations.

Can we achieve this?

Jeroen November 23, 2016 at 10:38 am

Hi Harsh,

There’s actually a example in the post which shows how you can setup the redirect rules per product.
If you want, I have created a extension that may be helpful, if you want more info, feel free to contact me.


sathish December 29, 2016 at 6:02 am

Actually we want “buy now” button in another website, If we clicked that button , We have to redirect to wocommerce product cart page , and aslo that product can be added to the cart. Is it possible

Nick Gray December 2, 2016 at 11:26 am

Cool mate, this is what i needed !!

markus hattenschweller January 26, 2017 at 9:03 pm

Hi Jeroen,
thanks for the great article.

When clicking on the add-to-cart-button, I want to redirect the customer to the checkout page. I added the following code as a variation and it’s working:

add_filter (‘add_to_cart_redirect’, ‘redirect_to_checkout’);

function redirect_to_checkout() {
return WC()->cart->get_checkout_url();

But only if the add-to-cart button is on the single-product-page of woocommerce.

When I add the shortcode [add_to_cart id=”post-id”] to a random page in wordpress, it’s not working…
Do you have a suggestion what I’m missing?
Thanks for helping out.

Jeroen January 27, 2017 at 9:19 am

Hi Markus,

I’ve got say that I’ve never used a add to cart shortcode before and haven’t looked at how that works / if it does anything differently.

Is it doing a ajax add to cart or a page refresh?


Mike February 15, 2017 at 1:54 am

What if you want to direct them to the cart only for some products, but for the rest, you want to use the AJAX option? For example, suppose I send a customer a link in an email that auto adds the item to the cart. I don’t want them to have to click a view cart button too. Is this possible?

Jeroen February 15, 2017 at 9:34 am

Hi Mike,

You could setup a conditional so it only applies to certain products, but I don’t think that would be best in your scenario as it would always go for those products and not only if you send them a link (well, you could also build that).


Tom March 21, 2017 at 5:54 pm

Hi, thanks you for awesome article!!

I have one additional question:
I want use one category ass “add accessories” before cart page. So I set up “add to cart” redirect to cart page (in Woo settings), than I add your code to redirect specific category to “accessories category page” and now I want keep users stay here until they click my continue button.

Does it possible disable redirects completely for certain category?
Should I combine Woo setting with code or should it be complex code, without Woo settings?

Thanks you

Rolf April 1, 2017 at 6:29 pm

If I have 200-300 products and at the cart, I want to redirect the products to another URL, what could we proceed?

Emily May 24, 2017 at 4:13 am

Thanks for the article!
I found a code that will allow the customer to be redirected to the parent category page after adding a product to their cart, but how do I redirect products to go to its subcategory instead?

Vy July 14, 2017 at 1:14 pm

Thanks for these tips above.

I have a use-case which is related and yet, somewhat unusual. Hoping you could comment on it/guide me?

I am trying to achieve the following:

Let’s say that user is in Page A. In this page, there’s a button, which onclick, takes user to checkout, after add-to-cart is enabled. Now, user is in checkout page, makes payment and comes to Thank you display.

I am wondering how to do any one of the following:
1. After checkout is successful, take user back to Page A
2. Embed Page A url within the Woo thank you page (perhaps replacing “Return to Shop” button url with Return to Page button url

Because, I want user to resume activity in the Page A, where user is visiting for a purpose.

Thanks in advance for any inputs/advice.

Eagan Heath August 6, 2017 at 6:36 pm

Thanks for the screenshots! That worked great.

Victor November 29, 2017 at 4:49 pm

Thanks for sharing this beautiful article. Its really help me to sort out my issue which is comming on webetutorial

Jonathan December 1, 2017 at 5:00 am

Hi Jerome,
Yet again, thanks for sharing another very useful tip.
It’s not quite behaving the way I would expect, and I am wondering if perhaps that’s because the tip is from 2015, and WC has changed a lot since then.
I am using the code you posted under “Redirect for certain products”. I have it redirecting to a WP page I have created.
Once the redirect occurs, it’s as though the add to cart process is incomplete. I can see in the little cart icon in my menu bar that there’s “1” item in there. But the cart in the side bar is blank. As soon as I browse to any WC page (a product or archive) it’s as though the Add To Cart completes it process. The ” X has been added to your cart.” message displays, and the sidebar cart is populated.
Now that I’ve spelt this out, I am thinking it’s because I am redirecting to a page and not a WC product or endpoint. Is there any way to get around that?

Jeroen December 1, 2017 at 10:20 am

Hi Jonathan,

When WC adds a product to the cart it also adds a notice. This notices stays in a sort of ‘queue’ until it has displayed.
The notices only display on WooCommerce pages by default, so thats why that notice appears later on.

Re the cart widget: this may actually be some caching related. I’ve just ran a test and it does appear to show in the cart widget for me on the default theme when adding from the single-product page (haven’t tested the archive/ajax add to cart).
Edit: just tested it on archive + ajax and both also seem to work.


Kristian Yates March 23, 2018 at 3:33 pm

This is great, Jerone. Just what I needed!

I wanted to create a product customiser with loads of options per section then submit as a single sale with an e-commerce facility.

Product customiser scipts just weren’t flexible enough, so I had the idea of using woo-commerce.

The first category is the base product followed by other categories showing each set of options.

I’ve hidden the categories menu and created a load of IF statements based on your code.
This allows me to take the visitor from category to category in the correct order and then to the checkout.

You’ve saved the day again!


Multiple IF code example:

// Only redirect products that have the ‘base’ category
if ( has_term( ‘base’, ‘product_cat’, $product_id ) ) {
$url = WC()->cart->get_checkout_url();

return $url = “”;

// Only redirect products that have the ‘colourfinish’ category
if ( has_term( ‘colourfinish’, ‘product_cat’, $product_id ) ) {
$url = WC()->cart->get_checkout_url();

return $url = “”;

// Only redirect products that have the ‘toe’ category to cart
if ( has_term( ‘sole’, ‘product_cat’, $product_id ) ) {
$url = WC()->cart->get_checkout_url();

return $url = “”;
add_filter( ‘woocommerce_add_to_cart_redirect’, ‘my_custom_add_to_cart_redirect’ );

Eri June 2, 2018 at 6:30 pm

Hi, Jeroen!
I’m looking for the way to completely switch off redirects on “add to cart”. For now it redirects on single product page or on the cart page. I do not need that. If i’m adding product from the archive page, just leave me there!
Could you, please, help with that?

Jeroen Sormani June 4, 2018 at 9:38 am

Hi Eri,

This is the default behaviour in WC that should already be the case. Make sure to remove all custom snippets from this post or any other you may have implemented that could redirect the user to the product page.
Note that there is a setting in the WC settings area that allow you to redirect to the cart after add, make sure to turn that off too.

– Jeroen

Monir June 13, 2018 at 12:32 pm

Hi, Jeroen.
This is very useful article indeed. But If I want to redirect only the specific product category products to cart page and other products will be added by AJAX add to cart buttons.
How can I do the above process?
Can you help me, please?

Jeroen Sormani June 13, 2018 at 5:53 pm

Hi Monir,

I’d recommend taking a look at my Add to Cart Redirect plugin then. That does support AJAX redirects, but do note that you’d configure it per product then, there’s no category based redirection option (yet).

Henrique Silva July 4, 2018 at 2:49 am


What place should I put the code that “John” mentioned in this question?
What if we want to redirect to product page after clicking on add to cart button?

Thank you

Jeroen Sormani July 4, 2018 at 8:09 am

Hi Henrique,

For implementation details I’d recommend taking a look at this post:


ravi singapuri July 13, 2018 at 3:05 pm

Great article ..! i got what i need exact

Jarkko Karhunen March 3, 2019 at 3:22 pm

Love the Redirect “for certain products” script. Thanks!

Wilehlm May 16, 2019 at 9:58 am


Do you know if this type url still works in the latest version of woo commerce where it adds the item and redirects to the cart?

I keep getting empty cart and nothing. The item is valid and everything seems to be setup correctly. This woo commerce seems to be a big@ss headache!

Jeroen Sormani May 17, 2019 at 10:20 am

Hi Wilhelm,

Yes this should still work.

jeremy July 7, 2019 at 9:43 pm


Is there a way to redirect to a list of a particular products cross-sells?

Jeroen Sormani July 8, 2019 at 10:50 am

Hi Jeremy,

Sure, if you list those products on a certain page with a ID attached to the section you can redirect users to there with a direct URL.

The hash sends someone to a section of the site using the ID of a tag on the page.


joseph August 8, 2019 at 11:44 am

Thanks for the code it worked fine, was looking for a way to redirect users to checkout page once they click on add to cart for some specific product and your post help me a lot thanks.

JL August 14, 2019 at 7:03 pm


can you help? i have a learnpress website, i want users to add the course to the cart and automaticlly send them to the cart.

I have tried everything but not working, with any of your codes will work? can you tell me how? thanks in advance

Steve Balmer September 1, 2019 at 3:16 pm

How do I redirect to the same category page the user has come from – after adding to cart is pressed.

Jeroen Sormani September 2, 2019 at 9:00 am

Hi Steve,

I’d recommend to do it using a `is_product_category()` check and then redirect back to the referrer page / get the link of the category.


Javier October 7, 2019 at 2:35 am

Hi Jeroen (I speak Dutch, so I can pronounce your name :P),

How to still get an added to cart message when using the custom redirect?

function my_custom_add_to_cart_redirect( $url ) {
$url = "STORE";
return $url;

I’m redirecting to the store but I sill want to get the message you get when redirected to cart saying “Stampot toegevoegd in de winkelwagen”.

i’m not using AJAX add to cart.


Jeroen Sormani October 7, 2019 at 9:51 am

Hi Javier,

By default the message should still appear after the add to cart redirect – if this is not the case there might be something else going on that I cannot answer without further investigation.


Alex January 17, 2020 at 2:32 am

Hey Jeroen,

Thank you for sharing your code. I appreciate the one where you show me how to redirect customers to the CHECKOUT when purchasing certain products.

I’m wondering if there’s a way to disable redirecting them to the CART when they click “buy now” on all the other products (so to keep them on the page they’re on and not send them off anywhere).

Thank you for your help!

Jeroen Sormani January 17, 2020 at 4:53 pm

Hi Alex,

There’s a setting in WooCommerce Core that enables directing users to the cart when adding to the cart; disable this setting to prevent it and only have the snippet trigger redirects.


Emilia November 25, 2020 at 6:07 am

This is very helpful, thank you. But can I redirect to a custom URL for only specific products?

Jeroen Sormani January 13, 2021 at 9:57 pm

Hi Emilia,

Of course, you can do this by adjusting the URL in the snippet.


Christopher West January 13, 2021 at 1:13 pm

Hi Jeroen

Happy New Year πŸ™‚

Great little code there.

It works for me on a product level but not with a product variation id.

Any thoughts?


Jeroen Sormani January 13, 2021 at 9:56 pm

Hi Chris,

It is possible to do this, you’d need to change the product_id check to the variation_id instead.
Alternatively, the Add to Cart Redirect plugin supports setting it based on variation as well πŸ˜‰


Christopher West January 14, 2021 at 4:08 am

Thanks Jeroen

Want to avoid another plugin to save costs.

My edited script is below but its not working. I have unchecked the Ajax checkbox. Your original code worked on the main product but that is never added to cart, only the variations are.

342 is one of the variation
847 is the page id to redirect the customer to to add other items to the cart.

What am I doing wrong? LOL. appreciate your help

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

if ( ! isset( $_REQUEST[‘add-to-cart’] ) || ! is_numeric( $_REQUEST[‘add-to-cart’] ) ) {
return $url;

$variation_id = apply_filters( ‘woocommerce_add_to_cart_product_id’, absint( $_REQUEST[‘add-to-cart’] ) );

// Only redirect the product IDs in the array to the checkout
if ( in_array( $variation_id, array( 341 ) ) ) {
$url = get_permalink( 847 ); // 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’ );

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 πŸ™‚ )

Leave a Reply