Giới hạn số lượng đặt hàng tối đa trong Woocommerce

0 bình luận

Ở bài viết này mình sẽ hướng dẫn các bạn cách giới hạn số lượng đặt hàng tối đa và tối thiểu cho một sản phẩm trong woocommerce. Để thiết lập giới hạn đặt hàng tối thiểu trong trang cart của woocommerce, bạn có thể sử dụng plugin hoặc custommer code mình sẽ hướng dẫn bên dưới.

WooCommerce-integration

1. Giới hạn số lượng sản phẩm tối đa các bạn có thể sử dụng plugin sau:

Maximum Purchase for WooCommerce

2. Giới hạn số lượng sản phẩm tối thiểu các bạn có thể sử dụng plugin sau:

Maximum Purchase for WooCommerce

Hoặc sử dụng đoạn code sau chèn vào file functions.php trong thư mục chứa theme. Nó sẽ chỉ cho phép khách hàng thanh toán nếu số lượng sản phẩm trong giỏ hàng của họ bằng hoặc lớn hơn 10

Đối với các phiên bản mới nhất của WooCommerce, sử dụng:

add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 10;
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->total )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->total )
), 'error'
);
}
}
}

Đối với WooCommerce phiên bản 2.0.x bạn nên sử dụng:

 add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
global $woocommerce;
$minimum = 10;
if ( $woocommerce->cart->get_cart_total() < $minimum ) {
$woocommerce->add_error( sprintf( 'You must have an order with a minimum of %s to place your order.' , $minimum ) );
}
}

Chúc các bạn thành công!

5/5 - (2 bình chọn)
guest
0 Bình luận
Inline Feedbacks
Xem tất cả bình luận