Redirect to Checkout after Adding Product to Cart
In this tutorial I will show you how to make WooCommerce “Add to cart” buttons to perform a redirect to the checkout page. And yes, we’re also going to change the button text.
It can be done in 4 simple steps. Let’s go!
1. Disable AJAX add to cart buttons
First of all we have to do some small configurations in WooCommerce Settings – Uncheck the “Enable AJAX add to cart buttons on archives” checkbox. That’s all.

Once done, let’s continue to the code part.
2. Change text on add to cart buttons
If you’re not sure where to insert the code – the best way is your custom plugin, if you do not know how to create one, then use your child theme functions.php
file, and the last option is your current theme functions.php
, which is not recommended if your theme receives updates periodically.
/*
* Change button text on Product Archives
*/
add_filter( 'woocommerce_loop_add_to_cart_link', 'misha_add_to_cart_text_1' );
function misha_add_to_cart_text_1( $add_to_cart_html ) {
return str_replace( 'Add to cart', 'Buy now', $add_to_cart_html );
}
/*
* Change button text on product pages
*/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'misha_add_to_cart_text_2' );
function misha_add_to_cart_text_2( $product ){
return 'Buy now';
}
I decided that str_replace()
for this situation is the most simple and easy solution, but if you do not want to use it, you can replace the first part of the code with this one:
/*
* Change button text on Product Archives
*/
add_filter( 'woocommerce_product_add_to_cart_text', 'misha_add_to_cart_text_1', 10, 2 );
function misha_add_to_cart_text_1( $text, $product ){
return $product->is_purchasable() && $product->is_in_stock() ? 'Buy Now' : 'Read more';
}
3. Redirect to Checkout Page
The main piece of code is here 🚀 I’ve seen many tutorials where just this piece of code is provided, but it is not enough of course.
/**
* Redirect to Checkout Page after Add to Cart @ WooCommerce
*/
add_filter( 'woocommerce_add_to_cart_redirect', 'misha_skip_cart_redirect_checkout' );
function misha_skip_cart_redirect_checkout( $url ) {
return wc_get_checkout_url();
}
Function wc_get_checkout_url()
returns the current URL of your checkout page. I know, you can obtain your checkout page URL directly with the help of get_permalink()
and get_option()
functions. The checkout page ID is stored in wp_options
under woocommerce_checkout_page_id
key by the way.
But I recommend to use wc_get_checkout_url()
in any way.
Fix for “Sold Individually” Products
I noticed one bug so. If your product is configured to be sold individually, like this:

Then, when you’re trying to add this product to the cart and it is already in the cart, your will receive this error message:

Certainly we do not want this message do be shown, do we?
My recommendation is simple – hook the add to cart url with woocommerce_product_add_to_cart_url
, check if the product is already in the cart and if so, replace the add to cart url with the checkout url. Easy peasy 🙃
add_filter( 'woocommerce_product_add_to_cart_url', 'misha_fix_for_individual_products', 10, 2 );
function misha_fix_for_individual_products( $add_to_cart_url, $product ){
if( $product->get_sold_individually() // if individual product
&& WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id( $product->id ) ) // if in the cart
&& $product->is_purchasable() // we also need these two conditions
&& $product->is_in_stock() ) {
$add_to_cart_url = wc_get_checkout_url();
}
return $add_to_cart_url;
}
4. Remove “The product has been added to your cart” message
Almost done, but…

Do not you think this message looks weird in our case? Let’s remove it with the code below
add_filter( 'wc_add_to_cart_message_html', 'misha_remove_add_to_cart_message' );
function misha_remove_add_to_cart_message( $message ){
return '';
}
That’s the complete solution. If the code doesn’t work for you or you have some questions, ask in comments below 👇

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Thanks so much for this. It’s working great.
You’re welcome! 🙃
Hi Thanks for the Code! It´s just what i needed.
I have a little problema.
I have added the “Fix for “Sold Individually” Products” but it didn´t work properly.
It always goes to the Product Page and I receive the message that “only one product can be added” but It should go to the checkout page instead of the product page, isn´t it?.
Thanks.
Yes, the Fix for “Sold Individually” Products isn’t working for me either. Stays on the product page and still shows the error.
Thanks, Buddy
It’s working.
Have a good day
For step 4, I had previously found this code, which works:
add_filter( 'wc_add_to_cart_message_html', '__return_false' );
Is there any reason I should use your code instead?
Technically your code is the same.
I have found a better way to avoid “You cannot add another…” error message. The suggested method from Misha don’t work in my setup. I use the
add_to_cart_validation
action hook to validate the add to cart action and redirect to checkout page on given conditions:Thanks! That fixed the error for me too :)
This doesn’t work for me…
Thanks!!! It works for me, have a great life!
Great work and thank you so much!
Thank you so much! That worked great. I did have to use @phlegx’s hook to prevent the “Already in Cart” error.
Hi!
For the Fix for “Sold Individually” Products this was worked for me case:
I try the two previous codes and neither worked for me, this was the snippet that did.
This last code worked like a charm for the individually sold products, even with AJAX still activated – thanks!
Thanks a lot! Fix my problem!
THANKS A LOT
Hi, great work above, but I still have one issue.
I want to add in the cart just one subscription and one or more product. In order to do that I have to enable in Woocommerce the following setting: “Allow multiple subscriptions and products to be purchased simultaneously. ”
But when I do that, I can add more than one subscription in the cart.
I want one subscription to be added in the cart and if another is added to replace the previous one. But this behavior needed only with subscriptions, not products.
Any ideas?
Hi,
You have to use the conditional statement:
tried this and getting error:
: Undefined variable $product_id in
how to fix?
Hi Mike,
to provide product id 🙃
Hi Misha,
Thanks for this.
In my case I used two buttons.
One for add to cart, and one for directly to checkout.
But why exactly do we have to disable AJAX to achieve this? It also seems to work fine with the checkbox still enabled.
Thanks again!
Thanks for pulling all the sensible stuff together.
I’ve done this before, but it’s a pain to go through bit by bit.