You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
82 thoughts on “WooCommerce: Redirect to Checkout on Add to Cart”
Thank you for the information, this has been very useful.
It worked after enabling “Redirect to the cart page after successful addition”. Thank you so much!
Uhm, should be the opposite actually
Actually it worked for me both ways, with and without the “Redirect to the cart page after successful addition” & “Enable AJAX add to cart buttons on archives“ activated.
I suppose is better to deactivate them as your instructions say?
Cool & yes
I’ve got a weird question, I know….in my woocommerce site, I haven’t added this script, however the behavior is the one you just explained: when the user adds a product (which is a single product, and it is a subscription), it is automatically redirected to the checkout page. However, I do NOT want this behavior, I want the user to go to the cart page…however, I cannot find what is causing the add-to-cart page make a redirect to /checkout/…..do you know what may be causing this?
Thanks in advance!
Could be a plugin or your theme. Disable everything to see which one is adding it. Anyhow, it is definitely possible to remove it in case, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Where should I add this code?
I am a little confused.
and one more will this work with a minimum-maximum purchase quantity plugin?
functions.php, as stated in the article. Yes, it will work, don’t see why not 🙂
This guide of WooCommerce redirection to the add cart is so helpful. I have also issues in the redirection.
Cool. What problems are you having?
It looks like this code works for WooCommerce v4+. Thanks, man!
It would be cool if there was a way to get rid of the “Product has been added to your cart” message on the checkout page.
Nice! You could use https://businessbloomer.com/woocommerce-remove-product-successfully-added-cart-message/
The redirection to the checkout page is not that simple before reading the article. I will try to set my Woocommerce according to this guide.
Still works, thanks Rodolfo!
Congratulations on your excellent work.
With this function I saved 179 dollars.
can help me be like this
redirect to the basket if adding the same product, or products that are already in the basket
not for other products, this is specifically for products that have been added to the basket, if I add a product that I have added or add 2x products, then it is switched directly to the basket
on the woocommerce single product and product page
Hi Ady, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Nice works great. Is there a way to ‘direct to checkout by product id with this code?
Hi Allen, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Just added it to my friends site – works great!
It still work.
I just created a Plugin with this code.
I was wrong. it works. and I was also able to change the function for the single product to make an upsell or a cross sell before checkout
for me not working 🙁
I’m looking to do this only for a specific product (a subscription), so if users add to cart a subscription they’re redirected to the checkout but if they choose a physical product they’re ain’t redirect elsewhere so they can continue their shopping.
Have you a snippet for this ? It would be very helpful 🙂
Hello Simon, I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know 🙂
It seems that this trick doesnt work on woo 3.6
First time when you add to cart is says “Payment not available when cart is empty”
Can you test it please?
Worked perfectly for me Cristian 🙂
Thanks the snippet still works, i used it on my site i wanted my product to be in checkout with a click of a buttons, thanks for this guild.
I am using this plugin for the redirect https://wordpress.org/plugins/add-to-cart-direct-checkout-for-woocommerce/
It also offers a product specific custom redirect on product basis and it also workes with Archive page Ajax add to cart
You are awesome man! 🙂
With regarding Woocommerce, when any issue appears to me that needs investigation, then I love to check 2 things with priority. Stackoverflow and your website with these great snippets. 🙂
Thank you so much! 🙂
This is a really good solution to have higher conversion. My problem is that the single product page of the WooCommerce is not a typical landing page. I would like to sell courses with woo. This solution works when the landing page is the product page itself as I see. (sorry if I am wrong I am not web designer or coder) I am looking for a solution to create a landing page and cta button on it with Divi than exchange the product page to this landing page in the woocommerce flow. In thsi case the visitor arrives to a custom landing page – push the Buy cta button, redirected to the checkout page of the chosen product.
Hello Satyi, thanks for your comment! This should help: https://businessbloomer.com/woocommerce-custom-add-cart-urls-ultimate-guide/
Awesome! Really Helpful, greeetings from Argentina…
thanks for your blog. You saved me a lot of time when I started to customize my first WordPress/WooCommerce site. I hopefully can give back a bit.
Another way to get the checkout url is the function wc_get_checkout_url(). Then the snippet looks like this:
This version should be version independent.
Olaf – thanks so much for your comment! Excellent feedback 🙂
Thanks a lot for it!.
It worked fine on desktop adding a product to cart from the product page, but failed to redirect to the checkout page on mobile environment (no errors, just stays on the product page)
What else do i have to look?
I’m using atelier theme
Thanks in advance
Hey Agustin, thanks for your comment! Try clearing your phone’s browser cache/cookies 🙂
Solved for me!
How can I redirect specific product to checkout page on click on add to cart button.
Hi Naveed, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know 🙂
This is exactly what I need but is there a way to use this snippit on a custom Elementor sales page?
Does it just copy directly into the custom CSS?
Hey Canneton, this should apply to every add to cart on your site. Just place this in your functions.php
working fine only thing that Facebook pixel doesnt track “add to cart” only skip and track checkout.
Hey Mike, maybe you can delay the redirect so that Facebook pixel fires 🙂
No longer working after latest update. Please suggest workaround?
Leland, it works perfect on Woo 3.3.3. Try to see if there’s something else that is causing that not to work 🙂
Like a charm.
not work for me
PHP version: 7.0.27
Hi there, thanks for your comment! I just tested this again with 3.3.1 and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?
Also, take a look at this tutorial to see how to troubleshoot: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/
Finally, can you try switching temporarily to “Twentyseventeen” or “Storefront” theme and let me know if it works?
Hope this helps!
I want to re-direct users to checkout when user click on ‘Add to cart’. i added your code in functions.php and also un-checked ajax checkbox of cart. But it’s not redirect the user to checkout page
agan, thanks so much for your comment! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R
Hello, what if i just want to re-direct users to the checkout for a single product? but keep all the other products as add to cart? Do you have code for this? Perhaps adding the product ID somewhere in the code in Functions.php?
Hey Jamie, I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know 🙂
This was AWESOME! It worked PERFECTLY and no plugins required! Thank you
Excellent, thanks Dustin 🙂
You rock – thanks!
Thank you Ben 🙂
You do an awesome job with all your snippets. I bet you help a lot of people and safe time for them. (even if they don’t respond).
This snippet works perfectly, except in one situation. When I enable the “Sold Individually” checkbox to limit the product to one per order. People don’t get redirect anymore when they try to add the product for the second time.
Is there a solution for this?
Hey Joke, thanks for your message! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R
This is a great little snippet.
Can it work with just one product?
Hey Steve thanks for your comment! Yes, of course, that can be done with conditional logic. I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know 🙂
I’ve added your Return to Checkout function and Rename Tab function to my child theme functions.php and nothing is showing up. How do I troubleshoot this? It is on a development site, not live site.
Hello Liz, thanks for your comment! Are your problems related to this snippet?