
When running an online store with WooCommerce, sometimes customers don’t want to go through the usual Add to Cart → View Cart → Checkout process. They just want to buy right away. That’s where a Buy Now button comes in — it skips the cart and takes users directly to the checkout page with their product ready to order. In this guide, I’ll show you how to add a custom Buy Now button to your WooCommerce product pages using a simple code snippet — no extra plugins needed.
🚀 Faster Checkout – Reduce clicks and speed up the buying process.
📈 Better Conversions – Perfect for impulse buys and one-product stores.
🎯 Customer Experience – Makes shopping easier for returning customers.
Copy and paste the following snippet into your theme’s functions.php file or (recommended) use the Code Snippets plugin to keep it organized and safe.
/**
* Custom "Buy Now" button functionality for WooCommerce.
*
* This code adds a "Buy Now" button to single product pages. When clicked,
* it clears the cart, adds the specified product with the selected quantity,
* and redirects the user directly to the checkout page.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Add a "Buy Now" button to the single product page, after the "Add to Cart" button.
*/
function arnob_add_buy_now_button() {
global $product;
if ( $product && ( $product->is_type( 'simple' ) || $product->is_type( 'variable' ) ) ) {
echo '';
}
}
add_action( 'woocommerce_after_add_to_cart_button', 'arnob_add_buy_now_button' );
/**
* Handle the "Buy Now" button click to add the product to the cart and redirect to checkout.
*/
function arnob_force_buy_now_redirect() {
if ( ! isset( $_REQUEST['buy_now'] ) ) {
return;
}
$parent_product_id = absint( $_REQUEST['buy_now'] );
$quantity = isset( $_REQUEST['quantity'] ) ? absint( $_REQUEST['quantity'] ) : 1;
$variation_id = isset( $_REQUEST['variation_id'] ) ? absint( $_REQUEST['variation_id'] ) : 0;
$product_id_to_add = $variation_id > 0 ? $variation_id : $parent_product_id;
if ( empty( $product_id_to_add ) ) {
return;
}
WC()->cart->empty_cart();
WC()->cart->add_to_cart( $product_id_to_add, $quantity );
wp_redirect( wc_get_checkout_url() );
exit;
}
add_action( 'template_redirect', 'arnob_force_buy_now_redirect' );
Adding a Buy Now button is a small change that can make a big difference for your WooCommerce store. It improves the user experience, reduces friction, and helps boost sales — especially for businesses selling gadgets, single products, or fast-moving items.