WooCommerce workflow can be a little too long for simple products, you can provide a better user experience, here’s how to get the product to skip past the cart page and go straight to the checkout page.
First, uncheck the cart options in WooCommerce Settings -> Products.
Then add in your functions.php
add_filter('woocommerce_add_to_cart_redirect', 'themeprefix_add_to_cart_redirect'); function themeprefix_add_to_cart_redirect() { global $woocommerce; $checkout_url = wc_get_checkout_url(); return $checkout_url; }
That’s it now when you click a product add to cart it will go to checkout.
Change the ‘Add to Cart’ label
Now since the cart is gone we should change the ‘Add to Cart’ label in the WooCommerce product to something a bit more immediate like ‘Pay Now’. WooCommerce has a filter for that too. This is also added to your functions.php
//Add New Pay Button Text add_filter( 'woocommerce_product_single_add_to_cart_text', 'themeprefix_cart_button_text' ); function themeprefix_cart_button_text() { return __( 'Pay Now', 'woocommerce' ); }
The above filter applies the text to the single product page, however, you may have the product on another post type, there is a 2nd filter you can also use – woocommerce_product_add_to_cart_text
//Add New Pay Button Text add_filter( 'woocommerce_product_single_add_to_cart_text', 'themeprefix_cart_button_text' ); add_filter( 'woocommerce_product_add_to_cart_text', 'themeprefix_cart_button_text' ); function themeprefix_cart_button_text() { return __( 'Pay Now', 'woocommerce' ); }
Now there are fewer steps to the end product purchase which makes the process simpler for the buyer.
29 comments
riya
Worked great for me also. However how can you REMOVE a product from the cart if you decide to change your selection before checking out?
Lisa
How can I use woocommerce without adding product? I want to create a invoice form and direct card payment to network international payment gateway please help me.
Grehgor
Hello, do you know how to effectively rename the “View Cart” button?
“$ translated_text;” did not work
shilpi
hello do you know how to redirect checkout page threw the cart icon.
Andreas Toll
much appreciated, thank you!
vk
You are the best!!
Thank you!!
Billy
You don’t need that php code. Just tweak the cart page to point to Checkout page in Woocommerce>Settings>Advanced.
Alauddin
How can I use woocommerce without adding product? I want to create a invoice form and direct card payment to network international payment gateway please help me.
virmat
Broke my site. I get HTTP ERROR 500. Removed the code from the functions.php file through SFTP and still can’t access the site or WP dashboard. PLEASE advise on how to fix. Thanks.
Mike Devis
Thank you for helping us. Can you please also tell how to create a sticky checkout that display the checkout page in a slider when customer clicks the cart page?
Neil Gowran
Lol
Joshua
Hi,
I am a non tech guy trying to set up my first booking website for accommodation’s. I have the bellevue child theme (hotel) and i have managed to set up the right calendar with a form and a book button.
After filling in the form I would like to get directly to the cart to proceed payment. On this screenshot (left) you can see how i managed to fix it. Screenshot (right) is how i want it to be and you will be directed to the cart : https://imgur.com/a/Mcxbd3r
I can’t figure out how this works: https://themovation.ticksy.com/article/7516
I hope somone can figure out explaining me how i can fix this.
Shane
First off: I can confirm this still works with Woocommerce 3.3.4
Second: It doesn’t seem like we need to pull down the $woocommerce global variable. Unless, that is, you have a particular reason for doing so. Mine works fine like this:
add_filter(‘woocommerce_add_to_cart_redirect’, ‘themeprefix_add_to_cart_redirect’);
function themeprefix_add_to_cart_redirect() {
$checkout_url = wc_get_checkout_url();
return $checkout_url;
}
Shane
And it might just be easier all around to simplify it to this:
add_filter(‘woocommerce_add_to_cart_redirect’, function () {
return wc_get_checkout_url();
});
carlos
How can I post the email of the buyer if I bypass the cart. Is there a way to pass it to checkout page by a hook?
David
Hiya
I love the first bit of code BUT how can you make that happen only for one product? It’s sending me mental trying.
rajkumar
thanks a ton
Bettina
Thank you for this post! This may be a stupid question, but where exactly do I input this .php file??
Chad
You need to put this inside of functions.php inside of your child theme.
Hetch
Worked great for me also. However how can you REMOVE a product from the cart if you decide to change your selection before checking out?
kas
Worked like a charm on the individual product pages, but still see the “Add to Cart” option on the default Shop page in Woo Commerce. Anyway to update the default purchase flow and button on the shop page too.
Stas
does themeprefix have to be replaced maybe? with the themename or what would be the exact value? thx.
Neil Gee
No the name ‘themeprefix’ does not need replacing that is a placeholder you can swap something more relevant to your theme name.
Stas
doesnt seem to work for me as well. maybe its conflicting with other woocommerce plugins like WooCommerce Germanized?
Robert
Neil,
Is this still working for you? I know this used to work but doesn’t appear to anymore. Is there by chance an updated snippet?
Thanks,
Robert
Neil Gee
Hi Robert – just checked one of the sites I am using it on and its still working ok – http://gradmentor.com.au/product/grad-mentor-assessment/
Tyler
Thanks for the post however for me this is just redirecting to the homepage. Any idea?
WooCamp
Tyler, it sounds like your pages are not set correctly in Woo’s Settings.
Navigate to WooCommerc > Settings > Checkout Tab, then look down the page for the heading of “Checkout Pages”. Make sure your cart and checkout pages are set correctly.
raheek
thanks a lot , but i want my add to cart botton lead to the chekout page not the product add to cart boutton because sometimes the client select so many products not only one ,