• 17/05/2022 • 3 phút đọc • 9 lượt xem

How to Add Buy Now Button in WooCommerce

Việt Lâm Coder
Việt Lâm Coder
Senior Fullstack & System Architect • Hotline: 0944.71.4545

There are two ways how to add buy now buttons to our WooCommerce store:


  • With a PHP function.

  • Using a plugin.


In this section, I will show you both ways, and let’s start with the first way, using a WordPress function.

Method #1: Use a function


The PHP function will add a quick buy now button to the right of the add to cart button.

Once a customer clicks on the Buy now button, they’ll be automatically redirected to the checkout page to complete the purchase of the selected product.

You’ll need to paste the code below inside the functions.php file of your child theme.

First, navigate to Appearance -> Theme Editor and click on the functions.php file from the list on the right.


Functions file


Then, scroll to the bottom of the file, paste the code below, and save the changes.
// Add buy now button to WooCommerce
function add_content_after_addtocart() {

$current_product_id = get_the_ID();

$product = wc_get_product( $current_product_id );

$checkout_url = wc_get_checkout_url();

if( $product->is_type( 'simple' ) ){
echo '<a href="'.$checkout_url.'?add-to-cart='.$current_product_id.'" class="buy-now button">Buy Now</a>';
}
}
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );



Paste the php function


Once saved, navigate to one of the products pages and click on the Buy Now button to verify that it’s working as expected.

Buy now button was added to single product


Please note that the code above will only work for a simple product and not for variable ones.


Adding a buy now button to products with multiple variations requires a complex code that defeats the purpose of using a function.

If you only have simple products in your store, you’re in luck and can defiantly use the code above. You can now move on and learn how to redirect customers after checkout.

However, if you’re also offering products with multiple variables, you better use a plugin.

Method #2: Use a plugin


Using a plugin is preferred to add a buy now button because it’s the easiest and works with any product type.

In addition, the new button will inherit the used theme’s style sheet and will look great out of the box.

In this article, we will use the Quick Buy Now Button for the WooCommerce plugin by Addify.

You can download the plugin from the official website for a total price or from us for only $4.99 (same plugin).

Once downloaded, navigate to Plugins -> Add New -> Upload and upload the plugin.


Upload quick buy now button plugin to WordPress


Once activated, the new Buy now button will be added to the products page next to the add to cart button.
Add buy now button with a plugin

By default, the button’s text will be Quick Buy, and clicking on it will add the product and redirect you to the cart page.

If you’re ok with it, keep it as is. However, you can modify the button and change its text and behavior.

The button’s settings


To customize the button’s behavior, navigate to WooCommerce -> Quick Buy Button.

WooCommerce buy now button plugin


Under the general and the button’s settings tabs, you’ll have many options related to the button.

For example, check the replace box if you would like to remove the default add to cart button altogether.


Replace add to cart button


To change the destination URL from the cart to the checkout page, expand the redirect location option and choose checkout.



In addition, you can also specify the categories where you would like to display the button.

To change the button’s text, navigate to the button settings tab and enter the Buy now text inside the label to change the quick buy text.


Replace button text to buy now


Additional options on this screen are hiding the shop page button or changing the buttons’ position.

Once you are done with the settings, save the changes and test the button.

Việt Lâm Coder

Việt Lâm Coder

Tác giả bài viết và chuyên gia quản trị website. Nếu bạn gặp khó khăn trong quá trình thực hiện hoặc có nhu cầu thiết kế website, lập trình web app Laravel, hãy liên hệ ngay với tôi qua Hotline / Zalo: 0944.71.4545.

☕ Mời Tác Giả Ly Cà Phê Ấm Lòng

Nếu bài viết này giúp ích cho công việc của bạn, hãy tiếp thêm động lực cho tác giả duy trì kho tri thức bằng một ly cà phê ấm lòng nhé!

Mã QR ủng hộ tác giả
Ngân hàng TMCP Quân Đội (MB Bank)TONG VIET LAM

Có Thể Bạn Quan Tâm

Cách Mở Tab Ẩn Danh Trên Safari MacBook Đơn Giản

Cách mở tab ẩn danh trên Safari MacBook sẽ giúp cho người dùng có thể bảo vệ quyền riêng tư và duyệt web một cách an toà...

Hướng dẫn 5 cách tắt update Windows 11 vĩnh viễn chi tiết nhất

Mặc định Windows 11 sẽ được tự động cập nhật trong nền. Tuy nhiên nếu vì lý do nào đó mà bạn không muốn nhận các bản...

Hướng dẫn trỏ file hosts cho domain trên hệ điều hành Windows

– Làm cách nào để 1 website có thể hoạt động trên Share hosting, VPS, Server mà không cần cấu hình các record DNS cho do...

Kích hoạt Cloudflare Turnstile trong Contact Form 7 chống spam

Cloudflare Turnstile là giải pháp xác thực không dùng CAPTCHA giúp bảo vệ website WordPress khỏi spam một cách nhẹ nhàng...

Cách Sử Dụng DeepSeek R1 Miễn Phí Trong Visual Studio Code Với Cline?

Hãy đối mặt với thực tế: Các trợ lý lập trình AI như GitHub Copilot thì tuyệt vời, nhưng chi phí đăng ký của chúng có th...

Gmail API – Tất cả những gì bạn cần biết - 2025

Nếu bạn đang tìm cách tích hợp Gmail vào các ứng dụng của riêng mình thì Gmail API chính là thứ bạn cần! Gmail là một lự...

Hướng dẫn tạo màn hình desktop ảo bằng Task View trên Surface Windows 11

Việt Lâm Coder sẽ hướng dẫn tạo lập nhiều màn hình desktop ảo bằng Task View trên Surface Windows 11 để sắp xếp các tác...

How to Transfer PuTTY Sessions To Another Windows Machine

his is an user contributed article. PuTTY is a terminal emulator application which can act as a client for the SSH, T...

Hướng dẫn cách kiểm tra cổng đang mở (Check open port) trên linux

Với nhiều năm kinh nghiệm hỗ trợ Khách hàng của Tenten, chúng tôi nhận thấy việc thường xuyên theo dõi kiểm tra hoạt độn...

Kiểm tra tất cả các port mà Cyber Panel đang cần có được mở hay không ?

Để kiểm tra tất cả các port cùng một lúc, bạn có thể sử dụng lệnh: netstat -tulpn | grep -E ':(8090|80|443|21|40110|401...

Hướng dẫn cài đặt KeyHelp Panel

Tóm tắt về KeyHelp Bạn đã có phần cứng tốt nhất cho các dự án Internet của mình nhưng việc quản lý phức tạp, hiệu suất...

Tổng hợp danh sách Control Panel VPS free tốt nhất hiện nay

Control Panel VPS free cung cấp một lựa chọn tuyệt vời cho những người dùng muốn quản lý VPS một cách dễ dàng và hiệ...