WooCommerce Skip Cart, Go Straight to Checkout Page
WooCommerce is a flexible, open-source eCommerce solution built on WordPress. Whether you’re launching a business, taking an existing brick and mortar store online, or designing sites for clients you can get started quickly and build exactly the store you want.
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.
Steps
- 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.
- 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.
Leave a Reply
You must be logged in to post a comment.