WooCommerce: Add Buy Now Button @ Single Product Page

If you’ve ever shopped on Amazon, you know how convenient it is to go straight from a product page to checkout with a single click. That “Buy Now” button eliminates extra steps and can make the buying process much faster. Inspired by this, I wanted to create something similar for WooCommerce stores — a simple button that lets your customers skip the cart and go straight to checkout, whether they’re buying a simple product or a single variation.

In this post, I’ll share a lightweight PHP + jQuery snippet that adds a “Buy Now” button right next to your standard “Add to Cart” button. The button dynamically updates if the product is a variable product or if the customer changes the quantity, ensuring that the checkout link is always accurate. With this solution, you can improve the user experience, reduce friction, and potentially increase conversions — all with just a few lines of code.

Add a Buy Now button to speed up checkout on WooCommerce product pages

PHP Snippet: Display “Buy Now” Button Beside the “Add to Cart” One on the WooCommerce Single Product Page

This snippet adds a “Buy Now” button right next to the standard “Add to Cart” button on WooCommerce single product pages. The button links directly to a checkout page with the selected product and a default quantity of one.

For variable products, it dynamically updates the link if a customer selects a variation, ensuring the correct variation ID is included. It also updates the link whenever the quantity input changes, so the checkout URL always matches the customer’s selection.

The button uses a small piece of jQuery, enqueued on the page, to listen for quantity and variation changes and adjust the link in real time. The result is a smoother shopping experience that allows customers to skip the cart and go straight to checkout while handling both simple and variable products seamlessly.

Note: this snippet is not compatible with variable products that use “Any…” attributes, nor with grouped products. It has not been tested with other product types.

/**
 * @snippet       Add "Buy Now" Button @ Woo Single Product Page
 * @tutorial      https://businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 10
 * @community     Join https://businessbloomer.com/club/
 */

add_action( 'woocommerce_after_add_to_cart_button', 'bbloomer_buy_now_button', 1 );

function bbloomer_buy_now_button() {
	
	global $product;
	$checkout_url = wc_get_checkout_url();
	$product_id = $product->get_id();
	$buy_now_url = esc_url( add_query_arg( 
		array( 
			'products' => $product_id . ':' . 1,
		),
		'/checkout-link/' 
	) );
	echo ' &mdash; OR &mdash; <a href="' . $buy_now_url . '" class="single_add_to_cart_button button buy_now_button" data-product-id="' . $product_id . '">Buy Now</a>';
	
	wc_enqueue_js( "

		function updateBuyNowURL() {
		
			var qty = $('form.cart').find('input.qty').val() || 1;
			var productId = $('a.buy_now_button').data('product-id');

			var variationId = $('form.cart').find('input[name=\"variation_id\"]').val();
			if (variationId && variationId !== '0') {
				productId = variationId;
			}

			var newUrl = '/checkout-link/?products=' + productId + ':' + qty;
			$('.buy_now_button').attr('href', newUrl);
			
		}

		// Quantity change
		$(document).on('change input', 'form.cart input.qty', updateBuyNowURL);

		// Variation change
		$('form.cart').on('show_variation hide_variation', updateBuyNowURL);

		// Initialize once on load
		updateBuyNowURL();

	" );
	
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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