Skip to content

Instantly share code, notes, and snippets.

@sisaacrussell
Created April 11, 2017 13:05
Show Gist options
  • Save sisaacrussell/af20e065b0af76cd5e59980912fc3173 to your computer and use it in GitHub Desktop.
Save sisaacrussell/af20e065b0af76cd5e59980912fc3173 to your computer and use it in GitHub Desktop.
Tribe Events Tickets - Limit RSVP to 1 per event
/*
* Tribe, limit ticket qty
* Source: https://theeventscalendar.com/support/forums/topic/only-one-ticket-per-person/
*/
function tribe_limit_tickets() {
?>
<script type="text/javascript">
jQuery(document).ready( function( $ ) {
// do this if tickets available
if ( $('.tribe-events-tickets').length ) {
// set max qty to 1
$('.tribe-events-tickets .tribe-ticket-quantity').attr('max', 1);
// run on input change
$('.tribe-events-tickets .tribe-ticket-quantity').change ( function ( ) {
// don't run the manually triggered change event
if ( $(this).val() == 0 ) return;
// make sure it's not more than 1
if ( $(this).val() > 1 ) $(this).val(1);
// change all inputs but this to 0
// manually trigger the change event so available stock gets updated
$('.tribe-events-tickets .tribe-ticket-quantity').not( $(this) ).val(0).change();
});
// add a oninput event
$('.tribe-events-tickets .tribe-ticket-quantity').on('input', function (e) {
$(this).change();
});
}
});
</script>
<?php
}
add_action('wp_head', 'tribe_limit_tickets');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment