Tính năng mua thêm hàng để nhận giao hàng miễn phí có thể thúc đẩy khách hàng mua sắm một cách tích cực để tăng doanh số bán hàng. Bài viết này sẽ hướng dẫn các bạn cách tích hợp tính năng này và thêm nút “Tiếp tục mua sắm” một cách dễ dàng.
Tính năng mua thêm để được miễn phí ship.
Bước 1: Tạo code chèn vào functions.php
Copy và paste đoạn code sau vào file functions.php trong child-theme nhé:
PHP
123456789101112131415161718 //Mua thêm để được freeshipadd_action( 'woocommerce_checkout_before_customer_details', 'hwp_free_shipping_cart_notice' );function hwp_free_shipping_cart_notice() {$min_amount = 500000; //Giá trị đơn hàng để được freeship$current = WC()->cart->subtotal;if ( $current < $min_amount ) {$added_text = 'Mua thêm ' . wc_price( $min_amount - $current ) . ' để được miễn phí vận chuyển!';$cart_total = WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax();printf( '<progress id="cart-progress-bar" max="500000" value="%s"></progress>', $cart_total );$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );$notice = sprintf( '<a href="%s" class="button-ms">%s</a> %s', esc_url( $shop_page_url ), 'Tiếp tục mua hàng', $added_text );wc_print_notice( $notice, 'notice' );}}
Bước 2: Tuỳ chỉnh CSS
CSS
1234 .button-ms{float:right;background-color:#000;padding:5px 10px;font-size: 12px;border-radius:8px;color:#fff;margin-top:-3px;margin-left:5px;}@media only screen and (max-width: 420px){.button-ms{margin-top: 8px!important;margin-left: 20px!important;}}
Kết quả
Chúc các bạn thành công!