How to Skip Cart and Redirect to Checkout Page WooCommerce

Skip Cart and Redirect to Checkout in WooCommerce
If you want to skip the cart and redirect to the checkout page in WooCommerce, you need to use a new redirect function that overrides the default WooCommerce add-to-cart button redirect options.

This is the common practice where you want to sell only one product on your WooCommerce site and there is no need for the cart page.

In other sites, you want to use the option to skip to the cart so that you increase the conversions since you reduce one step in the customer’s buying cycle.

There are several other reasons why you may want to skip the cart and redirect to the checkout page.

Add to Cart URL Redirect to Checkout Page

For example, I was recently building a WooCommerce pricing table for a client website.

There was no need for the cart page since each product is sold solely and when you pick one option the others are excluded.

WooCommerce Skip Cart, Go StraWooCommerce Skip Cart, Go Straight to Checkout Pageight to Checkout Page

In this case, the  best approach was to preload the add-to-cart with the product ID and a redirect to the checkout page as shown in these URLs:

Monthly: https://example.com/checkout/?add-to-cart=PRODUCT_ID

Quarterly: https://example.com/checkout/?add-to-cart=PRODUCT_ID

Yearly: https://example.com/checkout/?add-to-cart=PRODUCT_ID

These URLs should be added to the respective buttons and in an ideal situation, clicking on the button should redirect to the checkout page with the product added to cart.

Skip the Cart and Redirect to Checkout Code

To force the add-to-cart behavior to skip the cart and redirect to the checkout page, you need to add the following code snippet to your functions.php :

/**
 * Skip Cart and Redirect to Checkout 
 * Add to functions.php of child theme
 */ 

add_filter('woocommerce_add_to_cart_redirect', 'njengah_skip_cart_redirect_to_checkout_page');

function njengah_skip_cart_redirect_to_checkout_page() {
	
 global $woocommerce;
 
	$checkout_url = wc_get_checkout_url();
 
		return $checkout_url;
}

Finally, for this code to work, you need to ensure that the option to enable the skip cart and redirect to the checkout page is enabled in the WooCommerce settings as shown in the image below :

redirect to cart WooCommerce settings

This last option is very important in helping your code snippet to work. When you add the URLs to the buttons alone and this option is not checked the redirect to the checkout page will fail.

Similar Articles

Comments are closed.