o add a “Direct Order” button in WooCommerce, allowing users to purchase a product quickly without going through the cart process, you can follow these steps. This approach skips the cart and takes the user directly to checkout after clicking the button.
Option 1: Use a Plugin
There are several plugins available that can help you add a “Buy Now” or “Direct Order” button in WooCommerce:
- WooCommerce Buy Now Button: A plugin that allows you to add a “Buy Now” button that redirects customers straight to checkout.
- Direct Checkout for WooCommerce: This plugin allows you to skip the cart and go directly to checkout.
- WooCommerce One Page Checkout: This plugin provides a one-page checkout process.
Option 2: Custom Code (Without a Plugin)
If you prefer to manually add the functionality, you can add custom code to your theme.
Step 1: Create a Direct Checkout URL
Each WooCommerce product has a URL format that you can use to take the user directly to the checkout page. You can use the add-to-cart
query parameter along with the product ID.
https://yourwebsite.com/checkout/?add-to-cart=PRODUCT_ID
Replace PRODUCT_ID
with the actual product ID from WooCommerce.
Step 2: Add Custom “Buy Now” Button
You can add a custom button to the product page by modifying your theme’s functions.php
file.
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="' . $checkout_url . '?add-to-cart=' . $product->get_id() . '" class="button buy-now">Buy Now</a>';
}
This code adds a “Buy Now” button below the default “Add to Cart” button, and it directs the user to the checkout page.
Option 3: Modify WooCommerce Settings
You can also reduce the friction in the checkout process by changing a couple of WooCommerce settings:
- Redirect to the cart after successful addition:
- Go to WooCommerce > Settings > Products.
- Check Enable AJAX add to cart buttons on archives.
- Check Redirect to the cart page after successful addition if you want users to go directly to the cart (then they can easily proceed to checkout).
These options are useful if you don’t want to skip the cart but still want to streamline the process.
Would you like a specific solution, or more details on any of these approaches?
Option 4: WooCommerce Direct Checkout Plugin and Code
Step 1: First insert below code in Function.php of theme
// Code Start +++++++++++++++++++++++++++++++++++++++++
// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' );
function woocommerce_custom_single_add_to_cart_text() {
return __( 'অ্ডার করুন', 'woocommerce' ); // Replace "Buy Now" text with your own text
}
// To change add to cart text on product archives(Collection) page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( 'অ্ডার করুন', 'woocommerce' ); // Replace "Buy Now" text with your own text
}
// Code End
Step2: Install WooCommerce Direct Checkout Plugin by QuadLayers
>> Go to setting of the plugin and set according to below screenshot