Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

416
Vistas
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?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda