This snippet generates a secondary button “Buy Now’.
Introducing this button allows users to checkout more quickly as they skip the entire cart journey of the buying journey.
This is particularly useful if you sell just one product or if the new to add multiple products to the order is not needed.
Specifically, this snippet gets the Product ID and adds it to the cart using an add to cart URL.
However, to bypass the cart and go straight to the checkout (the whole point of the “Buy Now” function), we add the checkout endpoint to the URL.
/**
* Snippet Name: WooCommerce Buy Now Button
* Snippet Author: ecommercehints.com
*/
add_action ('woocommerce_after_add_to_cart_form', 'ecommercehints_buy_now', 10, 0);
function ecommercehints_buy_now() {
global $product;
if ( ! $product->is_type( 'simple' ) ) return; // Only show on simple products
echo 'Buy Now';
};