Created
April 29, 2016 20:22
-
-
Save elimn/30c533fad7ee5ce4c3cb8a0f727c7190 to your computer and use it in GitHub Desktop.
MT | ET | Force users to select at least one ticket or RSVP before submitting the form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Prevents users from adding tickets to cart unless they have selected at least one ticket | |
*/ | |
function tribe_prevent_add_cart_empty() { | |
echo ' | |
<script type="text/javascript"> | |
jQuery( document ).ready(function(){ | |
jQuery( "form.cart" ).each(function(){ | |
var tribe_empty_form_message = "Please select at least one item before submitting"; | |
var tribe_cart_submit_button = jQuery( this ).find( "button[type=submit]" )[0]; | |
var tribe_checkout_fields = jQuery( this ).find( "input[type=number]" ); | |
tribe_cart_submit_button.setCustomValidity( tribe_empty_form_message ); | |
tribe_checkout_fields.each(function(){ | |
jQuery( this ).on( "change", function(){ | |
for (var i = 0, total_tickets = 0; i < tribe_checkout_fields.length; i++) | |
total_tickets = total_tickets + parseInt(tribe_checkout_fields[i].value); | |
if( total_tickets > 0 ) | |
tribe_cart_submit_button.setCustomValidity( "" ); | |
else | |
tribe_cart_submit_button.setCustomValidity( tribe_empty_form_message ); | |
}); | |
}); | |
}); | |
}); | |
</script>'; | |
} | |
add_action( 'tribe_events_single_event_after_the_meta', 'tribe_prevent_add_cart_empty' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment