Coming soon with new templates!100% OFF

How to Add “Buy Now” Button on Product Page

ecommerce web design and development buy now button

In the fast-paced world of online shopping, speed is king. Offering your customers a quick purchasing experience can mean the difference between a sale and a cart abandonment. Today, I’ll walk you through how to zip your customers from “just browsing” to “just bought” by adding a “Buy Now” button to your WooCommerce site.

Benefits of the “Buy Now” Button

  • Speedy Sales: Whisk customers straight to the checkout page, turbocharging the buying process.
  • Fewer Abandonments: With no need to visit the cart page, the chance of customers bailing mid-way plummets.
  • Higher Conversions: A faster checkout usually translates to more sales. Cha-ching!

Step 1: Install the Code Snippets Plugin

The first thing you need to do to add a snow effect is to install a plugin called Code Snippets. This plugin allows you to add pieces of code, such as HTML, CSS, and Javascript, to your website. It also offers a toggle feature that lets you manage these codes and activate or deactivate them whenever you want. This feature helps you quickly enable certain codes to enhance your customer’s experience.

Step 2: Add a “Buy Now” Button with PHP

After installing the plugin, copy the HTML code provided below and create a new snippet in Code Snippets. When creating this snippet, remember to paste your code in the PHP section.

This freely available code is locked down.

Log in or create an account to access our magic code.

Sign Up / Login
/* Dynamic Button for Simple & Variable Product */

function sbw_wc_add_buy_now_button_single()
{
    global $product;
    printf( '<button id="sbw_wc-adding-button" type="submit" name="sbw-wc-buy-now" value="%d" class="single_add_to_cart_button buy_now_button button alt">%s</button>', $product->get_ID(), esc_html__( 'Buy It Now', 'sbw-wc' ) );
}

add_action( 'woocommerce_after_add_to_cart_button', 'sbw_wc_add_buy_now_button_single' );



/*** Handle for click on buy now ***/

function sbw_wc_handle_buy_now()
{
    if ( !isset( $_REQUEST['sbw-wc-buy-now'] ) )
    {
        return false;
    }

    WC()->cart->empty_cart();

    $product_id = absint( $_REQUEST['sbw-wc-buy-now'] );
    $quantity = absint( $_REQUEST['quantity'] );

    if ( isset( $_REQUEST['variation_id'] ) ) {

        $variation_id = absint( $_REQUEST['variation_id'] );
        WC()->cart->add_to_cart( $product_id, 1, $variation_id );

    }else{
        WC()->cart->add_to_cart( $product_id, $quantity );
    }

    wp_safe_redirect( wc_get_checkout_url() );
    exit;
}

add_action( 'wp_loaded', 'sbw_wc_handle_buy_now' );

/* Dynamic Button for Simple & Variable Product Closed */

Don’t forget to click “Save Changes and Activate”

Before:

After:

How It Works:

  1. Button Placement: The “Buy Now” button pops up right below the “Add to Cart” button on product pages.
  2. Cart Management: Clicking the button clears the current cart and adds the new product.
  3. Instant Checkout: Shoppers are instantly redirected to the checkout page.

Conclusion:

This nifty addition can enhance customer experience and boost your sales on your WooCommerce-powered e-commerce site. Follow the steps above to integrate the code into your site, and watch your customers breeze through their purchases. Happy selling!

Leave a Reply

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

Made in Flatsome