Product Page

WooCommerce Buy Now Button

WooCommerce buy now button redirecting to checkout

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

This snippet generates a secondary button “Buy Now’.

Introducing this button allows users to checkout more quickly as they skip the entire cart journey of the buying journey.

This is particularly useful if you sell just one product or if the new to add multiple products to the order is not needed.

Specifically, this snippet gets the Product ID and adds it to the cart using an add to cart URL.

However, to bypass the cart and go straight to the checkout (the whole point of the “Buy Now” function), we add the checkout endpoint to the URL.

/**
 * Snippet Name:	WooCommerce Buy Now Button
 * Snippet Author:	ecommercehints.com
 */

add_action ('woocommerce_after_add_to_cart_form', 'ecommercehints_buy_now', 10, 0);
function ecommercehints_buy_now() {
	global $product;
	if ( ! $product->is_type( 'simple' ) ) return; // Only show on simple products
	echo '<a href="/checkout?add-to-cart='.$product->get_ID().'" class="button">Buy Now</a>';
};

Snippet Benefits

  • Skip an entire step in the buying journey by bypassing the cart and send the user straight to checkout upon button click.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER