Thay vì người chuyển phải nhập thủ công Số tài khoản – Ngân hàng – Số tiền – Nội dung, thì bây giờ hãy dùng QR Code để quét thông tin chuyển khoản được nhanh chóng và thuận tiện. Tăng tỷ lệ chuyển đổi và tỷ lệ thanh toán trước, cũng giúp website trở nên chuyên nghiệp và uy tín hơn.
Sau đây mình sẽ hướng dẫn các bạn sử dụng VietQR để tích hợp tính năng này vào WooCommerce.

1. Cấu hình chuyển khoản ngân hàng trong WooCommerce
Trong WooCommerce đã có sẵn phần cấu hình phương thức thanh toán bằng hình thức chuyển khoản ngân hàng, truy cập vào WooCommerce -> Cài đặt -> Thanh toán -> Bật Chuyển khoản ngân hàng

Điền thông tin tài khoản vào các trường theo mẫu như trên, trong đó:
- Tên tài khoản: Viết hoa toàn bộ, không dấu
- Số tài khoản: Viết liền
- Tên ngân hàng: Ghi tên viết tắt của ngân hàng, Viết liền
- Mã BIC / Swift (nếu cần): dành cho nhận chuyển khoản quốc tế
Lưu thay đổi.
2. Thêm Code hiển thị mã QR thanh toán
Tiếp theo, các bạn sao chép đoạn code sau và đưa vào file functions.php
của theme bạn đang sử dụng. Nếu không thạo khi làm việc với các file, bạn cũng có thể chèn nó thông qua plugin Code Snippets để tránh phát sinh lỗi và code bị xóa mất lúc nâng cấp theme.
add_action('woocommerce_thankyou_bacs', function($order_id){
$bacs_info = get_option('woocommerce_bacs_accounts');
if(!empty($bacs_info) && count($bacs_info) > 0):
$order = wc_get_order( $order_id );
$content = 'Don hang ' . $order->get_order_number(); // Nội dung chuyển khoản
?>
<div class="vdh_qr_code">
<?php foreach($bacs_info as $item): ?>
<span class="vdh_bank_item">
<img class="img_qr_code" src="https://img.vietqr.io/image/<?php echo $item['bank_name']?>-<?php echo $item['account_number']?>-print.jpg?amount=<?php echo $order->get_total() ?>&addInfo=<?php echo $content ?>&accountName=<?php echo $item['account_name']?>" alt="QR Code">
</span>
<?php endforeach; ?>
<div id="modal_qr_code" class="modal">
<img class="modal-content" id="img01">
</div>
</div>
<style>
.vdh_qr_code{justify-content:space-between;display:flex}.vdh_qr_code .vdh_bank_item{width:260px;display:inline-block}.vdh_qr_code .vdh_bank_item img{width:100%}.vdh_qr_code .img_qr_code{border-radius:5px;cursor:pointer;transition:.3s;display:block;margin-left:auto;margin-right:auto}.vdh_qr_code .img_qr_code:hover{opacity:.7}.vdh_qr_code .modal{display:none;position:fixed;z-index:999999;left:0;top:0;width:100%;height:100%;background-color:rgba(0,0,0,.9)}.vdh_qr_code .modal-content{margin:auto;display:block;height:100%}.vdh_qr_code #caption{margin:auto;display:block;width:80%;max-width:700px;text-align:center;color:#ccc;padding:10px 0;height:150px}.vdh_qr_code #caption,.vdh_qr_code .modal-content{-webkit-animation-name:zoom;-webkit-animation-duration:.6s;animation-name:zoom;animation-duration:.6s}.vdh_qr_code .out{animation-name:zoom-out;animation-duration:.6s}@-webkit-keyframes zoom{from{-webkit-transform:scale(1)}to{-webkit-transform:scale(2)}}@keyframes zoom{from{transform:scale(.4)}to{transform:scale(1)}}@keyframes zoom-out{from{transform:scale(1)}to{transform:scale(0)}}.vdh_qr_code .close{position:absolute;top:15px;right:35px;color:#f1f1f1;font-size:40px;font-weight:700;transition:.3s}.vdh_qr_code .close:focus,.vdh_qr_code .close:hover{color:#bbb;text-decoration:none;cursor:pointer}@media only screen and (max-width:768px){.vdh_qr_code .modal-content{height:auto}}
</style>
<script>
const modal = document.getElementById('modal_qr_code');
const modalImg = document.getElementById("img01");
var img = document.querySelectorAll('.img_qr_code');
for (var i=0; i<img.length; i++){
img[i].onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
modalImg.alt = this.alt;
}
}
modal.onclick = function() {
img01.className += " out";
setTimeout(function() {
modal.style.display = "none";
img01.className = "modal-content";
}, 400);
}
</script>
<?php
endif;
});
3. Lưu lại và xem kết quả
Có thể thay nội dung chuyển khoản theo ý muốn ở trên. Giờ các bạn hãy thử đặt 1 đơn hàng và xem kết quả.
Click vào ảnh mã QR để phóng to:

Trong mã QR Code đã điền sẵn tất cả các thông tin, bao gồm:
- Tên ngân hàng
- Số tài khoản
- Chủ tài khoản
- Số tiền thanh toán bằng đúng giá trị đơn hàng
- Nội dung chuyển khoản là mã đơn hàng (cái này có thể thay đổi tuỳ chỉnh đoạn code trên)
Như vậy chỉ cần cấu hình và code 1 vài bước đơn giản là đã có thể tích hợp mã QR Code thanh toán vào trong WooCommerce một cách dễ dàng. Chúc các bạn thành công.
4. Bonus cách ấn phương thức giao hàng khách khi đủ điều kiện miễn phí giao hàng
Để hệ thống tự ẩn các phương thức giao hàng khác khi đơn hàng của khách đủ điều kiện sử dụng miễn phí giao hàng thì bạn chèn đoạn code sau vào functions.php của theme đang dùng (Giao diện -> Sửa -> functions.php):
Code 1: Ẩn phí vận chuyển khi có miễn phí vận chuyển.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
Code 2: Ẩn phí vận chuyển khi có miễn phí vận chuyển nhưng giữ nguyên “Nhận hàng tận nơi”
/**
* Hide shipping rates when free shipping is available, but keep "Local pickup"
* Updated to support WooCommerce 2.6 Shipping Zones
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
$new_rates = array();
foreach ( $rates as $rate_id => $rate ) {
// Only modify rates if free_shipping is present.
if ( 'free_shipping' === $rate->method_id ) {
$new_rates[ $rate_id ] = $rate;
break;
}
}
if ( ! empty( $new_rates ) ) {
//Save local pickup if it's present.
foreach ( $rates as $rate_id => $rate ) {
if ('local_pickup' === $rate->method_id ) {
$new_rates[ $rate_id ] = $rate;
break;
}
}
return $new_rates;
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
Nếu bạn dùng 1 trong 2 code trên để phù hợp với phiên bản WooCommerce bạn đang sử dụng.
Đây là một ví dụ ẩn các phương thức giao hàng khác khi miễn phí giao hàng có hiệu lực:
