Untitled
2 months ago in PHP
/**
* Define quantidade minima de compra
*/
function min_qtd_compra(){

$cart = WC()->cart;
$cart_total = 0;
$cart_quantity = 0;
$limit = 5; // limit

foreach( $cart->get_cart() as $cart_item ){
$cart_quantity += $item_qty;
$cart_total += $item_line_total;
}

if ( $cart_total > intval( $limit ) ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'Your current order quantity total of %s is %s — the maximum quantity you can order is %s ',
$product_name,
$product_number,
$howmuch
), 'error'
);
} else {
wc_add_notice(
sprintf( 'Your current order quantity total of %s is %s — the maximum quantity you can order is %s ',
$product_name,
$product_number,
$howmuch
), 'error'
);
}
}
}
add_action( 'woocommerce_checkout_process', 'min_qtd_compra' );
add_action( 'woocommerce_before_cart', 'min_qtd_compra' );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37