'Woocommerce Add to Cart Validation not working

I've got this code snippet:

function so_validate_add_cart_item( $passed, $product_id, $quantity, $variation_id = '', $variations= '' ) {
<script>
  jQuery(function($){
       jQuery(document).on('click', '.single_add_to_cart_button', function (e) {
            e.preventDefault();
            alert("Please select a quantity to add to the cart.");
       });  
    });
</script>
}
 add_filter( 'woocommerce_add_to_cart_validation', 'so_validate_add_cart_item', 10, 5 );

I've got multiple +/- quantity selection buttons and one add to cart button. How do I set this to not fire if a quantity was selected? Currently it fires if there is or isn't.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source