Add a “Buy Now” Button with One-Click Checkout in WooCommerce

Offering a faster purchase path can significantly improve conversion rates, especially for single-product purchases. With this simple snippet, you can add a “Buy Now” button beside the default “Add to Cart” button on your WooCommerce store, enabling a one-click checkout experience.

What This Does:

  • Adds a Buy Now button on simple product pages.
  • When clicked, it clears the cart, adds the selected product, and redirects the user directly to the Checkout page — skipping the cart.

Code Overview

1. Display Buy Now Button

This part hooks into the product page after the “Add to Cart” button and appends a “Buy Now” button with a custom query string.

add_action('woocommerce_after_add_to_cart_button', 'one_click_checkout_button');
function one_click_checkout_button() {
    global $product;

    if ($product->is_type('simple')) {
        $url = esc_url(add_query_arg([
            'one_click_checkout' => 'yes',
            'product_id' => $product->get_id()
        ], home_url()));
        echo '<a href="' . $url . '" class="button alt" style="margin-left:10px;">Buy Now</a>';
    }
}

2. Handle Redirection and Cart Logic

When the “Buy Now” button is clicked, it triggers a template_redirect action that:

  • Clears the current cart.
  • Adds the selected product to the cart.
  • Redirects the user to the checkout page.
add_action('template_redirect', 'handle_one_click_checkout');
function handle_one_click_checkout() {
    if (!isset($_GET['one_click_checkout']) || $_GET['one_click_checkout'] !== 'yes') return;

    $product_id = intval($_GET['product_id']);
    if (!$product_id) return;

    WC()->cart->empty_cart();
    WC()->cart->add_to_cart($product_id);

    wp_redirect(wc_get_checkout_url());
    exit;
}

Use Case

Perfect for:

  • Landing pages with a single product.
  • Promotions where you want customers to check out with fewer steps.
  • Mobile-first eCommerce stores.

This approach improves speed and convenience for users who want a streamlined buying experience.

Want help turning this into a plugin or adding variations and grouped product support?

Rashed Hossain
Rashed Hossain

As an experienced WordPress professional, I specialize in theme and plugin development with a robust background in product and project management. My commitment lies in delivering top-notch solutions that align with client needs and surpass expectations.

Articles: 24

Leave a Reply

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