WooCommerce: Redirect to Checkout on Add to Cart

Here’s how you force redirection to the checkout page every time a product is added to cart, no matter if you do so from the loop/shop pages or the single product page.

On top of adding the code to your functions.php you also need to double check your WooCommerce settings, see screenshot below. Enjoy!

Force Redirection to WooCommerce Checkout on Add to Cart

1. WooCommerce Settings

Go to WooCommerce > Settings > Products > General and disable both options: “Redirect to the cart page after successful addition” & “Enable AJAX add to cart buttons on archives“:

WooCommerce Settings to Allow for Checkout Redirect

2. PHP Snippet: Redirect to Checkout on Add to Cart – WooCommerce

/**
 * @snippet       Redirect to Checkout Upon Add to Cart - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    Woo 3.8
 * @community     https://businessbloomer.com/club/
 */
 
add_filter( 'woocommerce_add_to_cart_redirect', 'bbloomer_redirect_checkout_add_cart' );

function bbloomer_redirect_checkout_add_cart() {
   return wc_get_checkout_url();
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Custom Add to Cart URLs – The Ultimate Guide
    In WooCommerce you can add a product to the cart via a custom link. You just need to use the “add-to-cart” URL parameter followed by the product ID. This tutorial will show you how to create custom URLs to add simple, variable and grouped products to the cart – as well as defining the add […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce: How to Fix the “Cart is Empty” Issue
    For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example). But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or […]
  • WooCommerce: “You Only Need $$$ to Get Free Shipping!” @ Cart
    This is a very cool snippet that many of you should use to increase your average order value. Ecommerce customers who are near the “free shipping” threshold will try to add more products to the cart in order to qualify for free shipping. It’s pure psychology. Here’s how we show a simple message on the […]
  • WooCommerce: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]

Rodolfo Melogli

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. Follow @rmelogli

82 thoughts on “WooCommerce: Redirect to Checkout on Add to Cart

  1. Hello,

    Thank you for the information, this has been very useful.

  2. It worked after enabling “Redirect to the cart page after successful additionโ€. Thank you so much!

    1. Uhm, should be the opposite actually

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

  3. Hi!
    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!

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

  4. Where should I add this code?
    I am a little confused.
    and one more will this work with a minimum-maximum purchase quantity plugin?

    Thanks.

    1. functions.php, as stated in the article. Yes, it will work, don’t see why not ๐Ÿ™‚

  5. This guide of WooCommerce redirection to the add cart is so helpful. I have also issues in the redirection.

    1. Cool. What problems are you having?

  6. It looks like this code works for WooCommerce v4+. Thanks, man!

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

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

    1. Cool

  8. Still works, thanks Rodolfo!

    1. Prego!

  9. Congratulations on your excellent work.
    With this function I saved 179 dollars.

    1. Nice!

  10. Hi,
    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
    thank you

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

  11. Nice works great. Is there a way to ‘direct to checkout by product id with this code?

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

  12. Just added it to my friends site – works great!

    1. Great!

  13. It still work.
    I just created a Plugin with this code.

    1. Nice!

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

    /**
    * @snippet Redirect to Checkout Upon Add to Cart โ€“ WooCommerce
    * @how-to Get CustomizeWoo.com FREE
    * @sourcecode https://businessbloomer.com/?p=21607
    * @author Rodolfo Melogli
    * @compatible Woo 3.5.3
    * @community https://businessbloomer.com/club/
    */
    
    function bbloomer_redirect_checkout_add_cart( $url ) {
    if ( is_single( โ€˜product idโ€™ ) ) {
    $url = get_permalink( post_id or product_id);
    return $url;
    }else{
    return $url;
    }
    }
    
    add_filter( โ€˜woocommerce_add_to_cart_redirectโ€™, โ€˜bbloomer_redirect_checkout_add_cartโ€™ );
    
    1. Great!

  15. for me not working ๐Ÿ™

  16. Hello Rodolfo,

    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 ๐Ÿ™‚

  17. Hi Rodolfo,

    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?

    Thank you

    1. Worked perfectly for me Cristian ๐Ÿ™‚

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

    1. Great!

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

    1. Cool, thanks!

  20. Hi Rodolfo!
    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. ๐Ÿ™‚

    Great work!
    Thank you so much! ๐Ÿ™‚

    1. Thank you!

  21. Hi Rodolfo,
    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.

    1. Hello Satyi, thanks for your comment! This should help: https://businessbloomer.com/woocommerce-custom-add-cart-urls-ultimate-guide/

  22. Awesome! Really Helpful, greeetings from Argentina…

    1. Genial!

  23. Hello Rodolfo,
    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:

     
    function my_add_to_cart_redirect() {
        $checkout_url = wc_get_checkout_url();
        return $checkout_url;
    }
    add_filter('woocommerce_add_to_cart_redirect', 'my_add_to_cart_redirect', 10, 1 );
    

    This version should be version independent.

    1. Olaf – thanks so much for your comment! Excellent feedback ๐Ÿ™‚

  24. Hi Rodolfo,

    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

    Agustin

    1. Hey Agustin, thanks for your comment! Try clearing your phone’s browser cache/cookies ๐Ÿ™‚

      1. Solved for me!

        1. Nice

  25. Hi,

    How can I redirect specific product to checkout page on click on add to cart button.

    1. 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 ๐Ÿ™‚

  26. Hi,

    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?

    1. Hey Canneton, this should apply to every add to cart on your site. Just place this in your functions.php

  27. woow awesome

  28. worked 3/16/2018

  29. working fine only thing that Facebook pixel doesnt track “add to cart” only skip and track checkout.

    1. Hey Mike, maybe you can delay the redirect so that Facebook pixel fires ๐Ÿ™‚

  30. No longer working after latest update. Please suggest workaround?

    1. Leland, it works perfect on Woo 3.3.3. Try to see if there’s something else that is causing that not to work ๐Ÿ™‚

  31. Like a charm.
    WC 3.3.1
    WP 4.9.4
    php 7.0.27

  32. not work for me
    woocommerce 3.3.1
    PHP version: 7.0.27

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

      R

  33. Hello,
    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

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

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

  35. This was AWESOME! It worked PERFECTLY and no plugins required! Thank you

    1. Excellent, thanks Dustin ๐Ÿ™‚

  36. You rock – thanks!

    1. Thank you Ben ๐Ÿ™‚

  37. Hello Rodolfo,

    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?

    Kind Regards,
    Joke

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

  38. Hi Rodolfo,
    This is a great little snippet.
    Can it work with just one product?

    1. 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 ๐Ÿ™‚

  39. Hi Rodolfo,
    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.

    1. Hello Liz, thanks for your comment! Are your problems related to this snippet?

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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