I’m developing a very special ecommerce that allows the insertion of up to 21 products in the cart.
How do I show a progress bar in the cart to show users how close they are to the limit.
Thank you
I managed to put a limit on it by inserting the following code, but you’ll want to make it a little more graphical with a progress bar
add_filter( 'woocommerce_update_cart_validation', 'only_six_items_allowed_cart_update', 10, 4 );
function only_six_items_allowed_cart_update( $passed, $cart_item_key, $values, $updated_quantity ) {
$cart_items_count = WC()->cart->get_cart_contents_count();
$original_quantity = $values['quantity'];
$total_count = $cart_items_count - $original_quantity + $updated_quantity;
if( $cart_items_count > 21 || $total_count > 21 ){
// Set to false
$passed = false;
// Display a message
wc_add_notice( __( "You cannot have more than 21 books in your cart", "woocommerce" ), "error" );
}
return $passed;
}