#2914
Soft79
Keymaster

Try pasting this in functions.php:


add_filter('woocommerce_coupon_is_valid', function ( $valid, $coupon, $wc_discounts = null ) {
    $wrap_coupon = WJECF_Wrap( $coupon );
    if ( $valid && $wrap_coupon->get_code() == 'your_coupon_code' ) {
        $items = WJECF_WC()->get_discount_items( $wc_discounts );

        $qty = 0;
        foreach( $items as $item_key => $item ) {
            if ( $item->product === false ) continue;
            $qty += $item->quantity;
            if ($qty > 1) throw new Exception( WC_Coupon::E_WC_COUPON_NOT_APPLICABLE ); // Max amount of items is 1
        }
    }
    return $valid;
}, 10, 3 );

Replace your_coupon_code with the actual coupon code.
Then the coupon will invalidate if amount of items in cart > 1