WooCommerce cart order limit based on product category quantity, weight and different products

I’m stumped at the moment as I’ve looked everywhere online as to how to limit the amount of products in your cart based on the quantity of the product category, the total weight of the cart and the amount of different products in the cart for Woocommerce in WordPress. Below are the rules I need to implement that restricts the customer from buying x amount of this, etc.

  • Vitamins: have a limit of 3 for each item
    I can do this as I have these plugins installed WooCommerce Advanced Product Quantities and Woocommerce Min/Max Quantities. But they can’t help me with the others as they don’t limit the quantity based on category only per product i.e. Formula Milk, cart max 6 but it allows 6 per product making it 12 if you order 2 products)
  • Formula Milk: Maximum quantity of 6.
  • Adult Milk Powder: Maximum quantity of 8.
  • Wash Supplies: Maximum 3 different items. Total quantity cannot exceed more than 10 pieces and a maximum weight of 3.5kg.
  • Food: Total quantity cannot exceed more than 18 pieces and a maximum weight of 4kg.
  • Cosmetic: Cannot exceed a maximum weight of 1kg. A single item has a maximum of 3 pieces
  • Mixed Items: In the cart you cannot have more than 7 different items, each item’s maximum quantity is 6 pieces. Total quantity cannot exceed more than 12 pieces and a maximum weight of 3.5kg.
    Lower quantities will stay the same i.e. Vitamins stays at 3, food is limited to 6 from 18, and the total sum of all item quantities in the cart is limited to 12. So you can have as a maximum:
    • Product #1: 1 Food
    • Product #2: 2 Vitamin #1
    • Product #3: 3 Vitamin #2
    • Product #4: 3 Cosmetic #1
    • Product #5: 1 Cosmetic #2
    • Product #6: 1 Milk Formula
    • Product #7: 1 Adult Milk Powder
  • Max 7 different products, total quantity of 12 and max weight of 3.5kg. This last rule will override a couple of the other rules.

If any of these rules are breached then a wc_notice should show up and state what is wrong, and stop them from adding to cart/proceeding to checkout.

Read More

So this is my dilemma, I know how to read the custom jquery when provided but I don’t know how I can do this, and my wordpress php knowledge is limited so I don’t know how to create actions but can again sort of read and understand it.

Any help is appreciated, if you find a plugin that will do something like this too please let me know. Thanks for your time and sorry about the length of the question.

Kind Regards

Edit:

I’ve thought maybe I can use this code in some way but instead of minimum convert it to maximum.

Woocommerce: Set minimum Order if Cart contains some Products / Category

Related posts