Untitled
2 years 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' );