I’m wanting to limit the number of products in my cart to 6 maximum.
All products in my woocommerce setup are sold singularly (cannot buy multiples of the same product).
Example of Cart
Is there a way of limiting the cart to 6 products? So if the user goes to add a 7th, a warning will pop-up ‘Maximum of 6 products only. Please remove a product from your cart’?
Tried googling, but could only find this, limited to a singular product: Need Woocommerce to only allow 1 product in the cart
It is the same procedure as the other question you linked to. On the validation filter, check the cart contents, and return a message if your requirements aren’t met. As mentioned, you would indeed use
get_cart_contents_count()
to count the number of line items in the cart.Edited: remove
empty()
check on cartAdded: validation on cart update