If you want customers to skip the cart page and go straight to checkout, adding a “Buy Now” button is a great way to speed up the purchase process — and you don’t need a plugin to do it.
Let’s break it down step by step.
Step 1: Add Custom Code to Your Theme
You’ll be adding a simple function to your theme’s functions.php file or a custom plugin (recommended if you want to keep the change even after updating the theme).
Go to your WordPress dashboard:
- Navigate to Appearance → Theme File Editor
- Open
functions.php - Paste this code at the bottom:
// Add "Buy Now" button on product pages
add_action( 'woocommerce_after_add_to_cart_button', 'add_buy_now_button' );
function add_buy_now_button() {
global $product;
$checkout_url = wc_get_checkout_url();
echo '<a href="' . esc_url( add_query_arg( 'buy-now', $product->get_id(), $checkout_url ) ) . '" class="button buy-now-button" style="margin-left:10px;background:#28a745;color:#fff;">Buy Now</a>';
}
// Handle Buy Now action
add_action( 'init', 'process_buy_now_action' );
function process_buy_now_action() {
if ( isset( $_GET['buy-now'] ) ) {
$product_id = intval( $_GET['buy-now'] );
WC()->cart->empty_cart();
WC()->cart->add_to_cart( $product_id );
wp_safe_redirect( wc_get_checkout_url() );
exit;
}
}
Step 2: Style the Button (Optional)
If you want to customize how the button looks, you can add a few CSS tweaks:
Go to Appearance → Customize → Additional CSS and paste:
.buy-now-button:hover {
background-color: #218838;
color: #fff;
}
You can change the color to match your site’s theme.
How It Works
- The Buy Now button appears next to the “Add to Cart” button.
- When clicked, it clears the cart, adds the selected product, and takes the customer straight to checkout.
Bonus Tip
If you want the “Buy Now” button to appear on the shop or category pages, you can modify the hook like this:
add_action( 'woocommerce_after_shop_loop_item', 'add_buy_now_button' );
Final Thoughts
That’s it — no plugins, no bloat. Just a clean “Buy Now” button that gets the job done fast.
Simple tweaks like this make a big difference in conversion rate and user experience.
Would you like me to add a version where users can buy a variable product directly with the “Buy Now” button too?