/** * Minimum bestelhoeveelheid per 2 stuks voor specifieke categorieën * Compatibel met WooCommerce + Breakdance */add_filter( 'woocommerce_quantity_input_args', 'vniels_quantity_rules', 20, 2 ); function vniels_quantity_rules( $args, $product ) {// categorie slugs waarop de regel geldt $target_cats = array( 'eetkamerstoelen-label51', 'eetkamerstoelen', 'stoelen' );// Controleer of product in één van die categorieën zit if ( has_term( $target_cats, 'product_cat', $product->get_id() ) ) { $args['min_value'] = 2; // minimaal 2 $args['step'] = 2; // alleen veelvouden van 2 $args['input_value'] = max( 2, $args['input_value'] ); // standaard 2 tonen }return $args; }// ✅ Controle in winkelwagen + checkout add_action( 'woocommerce_check_cart_items', 'vniels_check_cart_quantities' ); function vniels_check_cart_quantities() {$target_cats = array( 'eetkamerstoelen-label51', 'eetkamerstoelen', 'stoelen' ); $error = false;foreach ( WC()->cart->get_cart() as $cart_item ) { $product = $cart_item['data']; $qty = $cart_item['quantity'];if ( has_term( $target_cats, 'product_cat', $product->get_id() ) ) { if ( $qty < 2 || $qty % 2 !== 0 ) { $error = true; wc_add_notice( sprintf( 'Het product "%s" moet per minimaal 2 stuks en in veelvouden van 2 besteld worden.', $product->get_name() ), 'error' ); } } }if ( $error ) { wc_add_notice( 'Pas de aantallen aan voordat je verder gaat met afrekenen.', 'error' ); } }
Toont alle 18 resultaten