Created
August 28, 2017 22:23
-
-
Save jentheo/e67ebb9aeea2433c686027176f4c3673 to your computer and use it in GitHub Desktop.
Limit the number of tickets user can select on event page
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
/* Tribe, limit ticket qty */ | |
function tribe_limit_tickets() { | |
?> | |
<script type="text/javascript"> | |
jQuery(document).ready( function( $ ) { | |
// do this if tickets available | |
if ( $('.available-stock').length ) { | |
// set max qty to 2 | |
$('.tribe-events-tickets .qty').attr('max', 2); | |
// run on input change | |
$('.tribe-events-tickets .qty').change ( function ( ) { | |
// don't run the manually triggered change event | |
if ( $(this).val() == 0 ) return; | |
// make sure it's not more than 2 | |
if ( $(this).val() > 1 ) $(this).val(2); | |
// change all inputs but this to 0 | |
// manually trigger the change event so available stock gets updated | |
$('.tribe-events-tickets .qty').not( $(this) ).val(0).change(); | |
}); | |
// add a oninput event | |
$('.tribe-events-tickets .qty').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