WooCommerce

Woocommerce: Skip the product page and cart page to go straight to checkout

Online-ShoppingIf your are selling an ebook or tickets via woocommerce and you want your buyer to go straight to checkout instead of product page and cart when click on product link.
if you want your buyer click on link or button to buy product from any page or post add a product to the cart without even visiting the product page and skip the cart page.

Well this can be done by adding a link on the page or post and being redirected to the checkout directly with the product being added to the cart automatically.

Skip the product page and cart page to go straight to checkout

Simply add a link on your page or post

http://your-site.com/?add-to-cart=37

For Example: <a href=”http://your-site.com/?add-to-cart=37″>Buy Now</a>

Replace http://your-site.com with your homepage URL and 37 by your product ID

Then add the following code to your functions.php file within your theme folder

/* woocommerce skip cart and redirect to checkout. */
function woocommerce_skip_cart() {
	$checkout_url = WC()->cart->get_checkout_url();
	return $checkout_url;
}
add_filter ('woocommerce_add_to_cart_redirect', 'woocommerce_skip_cart');

code_canyon_728x90

Skip cart page for certain products only?

If you want to skip the cart page for specific products only, then add the following code.
You customers can go to the direct checkout page from the product page

/* woocommerce skip cart and redirect to checkout for specific product. */
function woocommerce_skip_cart() {
global $woocommerce;
$product_id = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $_POST['add-to-cart'] );

if ( $product_id == 32787 || $product_id == 32827 ) {
	$checkout_url = WC()->cart->get_checkout_url();
	return $checkout_url;
}
}
add_filter ('woocommerce_add_to_cart_redirect', 'woocommerce_skip_cart');

The above code will skip the cart page for 2 products with ids 32787 & 32827. Don’t forget to change the ids to your product ids when you copy the above code.

One thought on “Woocommerce: Skip the product page and cart page to go straight to checkout

  • Thank you – this is just what I’ve been looking for! Works perfectly

    Reply

Leave a Reply

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