Remove WooCommerce Cart Condition (Minimum Amount of a Product)

i'm a bit stuck for this.. i'm trying to remove a condition whenever the user adds a specific product, in this case a box of wines

enter image description here

So when i add a bottle of wine there's a minium amount condition so you have to add 3, but when you add a box the condition must be removed

add_action('woocommerce_after_cart_contents', 'box_special_function', 1, 1);

function box_special_function()
{
// getting cart items
    $cart = WC()->cart->get_cart();
    
    $terms = [];
// Getting categories of products in the cart
    foreach ($cart as $cart_item_key => $cart_item) {
        $product = $cart_item['data'];
        $terms[] = get_the_terms( $product->get_id(), 'product_cat' );
    }
// Cycling categories to find if there is a box inside of the cart
    foreach($terms as $term => $item){
        foreach($item as $key){
            if($key->name == "BOX"){
                // The only thing i did is to remove notices (which doesn't even work .-.)
                $notices = WC()->session->get('wc_notices', array());
                
                foreach($notices['error']){
                    wc_clear_notices();
                }
            }
        }
    }
    
}

I can't even force to checkout so i'm stuck with this.. can somebody clear my mind?

Solutions

You can update your minimum product add to cart functionality, and remove validation for your specific products like this:

add_filter( 'woocommerce_quantity_input_args', 'custom_woocommerce_quantity_changes', 10, 2 );

function custom_woocommerce_quantity_changes( $args, $product ) {
    $product_id = $product->get_id();
    $product_title = $product->get_title();
    //echo "<pre>"; print_r($product_title); echo "</pre>";
    if($product_id == 1002 || $product_title == 'BOX'){
        $args['input_value'] = 1; 
        $args['min_value'] = 1; 
        $args['max_value'] = 30;
        $args['step'] = 1;
    }else{
        $args['input_value'] = 3; // Start from this value (default = 1) 
        $args['max_value'] = 30; // Max quantity (default = -1)
        $args['min_value'] = 3; // Min quantity (default = 0)
        $args['step'] = 1; // Increment/decrement by this value (default = 1)
    }
    return $args;
}

print your specific product id or product name and use same name or id in your if condition :

if($product_id == 1002 || $product_title == 'BOX')

For rest of product set min, max and input product validation from "else" parts.

Similar questions

WooCommerce minimum order amount for specific country excluding local pickup
I am trying to craft a code for WooCommerce to set a minimum order amount for specific countries, but I want to let them order if they select "local pickup" as their shipping method. Nevertheless, I can't make it work. I tried to look it up but couldn't find a post which explained it. I hope that you can give me some insights. Thanks alre...
How to get minimum order amount for free shipping in woocommerce
How can i fetch minimum order amount required to get free shipping ( woocommerce_free_shipping_min_amount which is set in admin panel woocommerce -> settings -> shipping -> free shipping -> minimum order amount ) in woocommerce? I want to display this price in front-end page
how to set different minimum order amount for free shipping for different user roles in woocommerce
I want to set different minimum order price for different user roles for free shipping. How can I implement it? I am currently using the below code. filter_woocommerce_available_shipping_methods() function:
Wordpress: Woocommerce - How do I display the proceed to checkout button only when the minimum amount is reached?
I am experiencing an issue, I don't want the checkout button until and unless the minimum amount for the sale has been met. In this case I don't want the total amount to be less that 250. I will post my code below, I would really be grateful if I can get this to work. CODE: This is my attempt for the above issue but it isn't working. UPDATE: I will...
Set minimum Order amount for specific Products or Categories in WooCommerce
I've searched extensively to see if other folks had this situation and received an answer with no luck. Essentially, I have two items customers can add to their cart. I want to make it so they cannot checkout with either of those items if their subtotal is not $15 or more. Having the ability to just drop their IDs into the code would be fine. Or, I...
How to get the minimum amount for free-shipping in Woocommerce 2.6
After the upgrade to Woocommerce 2.6 , I decided to use the new Shipping Zones functionality I have broken a function of mine calculating the difference from cart value in order to get free shipping. I used to get the free shipping value like : But now as things have changes , i want to use shipping zones. So how can I get the min amount required f...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.