Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Last active February 7, 2024 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrasguseo/ad3afe83837c1f777bb76ab845731339 to your computer and use it in GitHub Desktop.
Save andrasguseo/ad3afe83837c1f777bb76ab845731339 to your computer and use it in GitHub Desktop.
ET > Make a ticket quantity selector step by 2
<?php
/**
* Make a ticket quantity selector step by 2.
*
* Usage: Add the snippet to your functions.php file or with a plugin like Code Snippets.
*
* @author: Andras Guseo
*
* Plugins required: Event Tickets
* Created: February 7, 2024
*/
function et_ticket_step_two() {
if ( is_admin() ) {
return;
}
if ( get_post_type() != 'tribe_events' ) {
return;
}
?>
<script>
// Add here the post IDs of the tickets which you want to have step by 2.
let tickets = [ '251', '252' ];
let selectorString = '';
tickets.forEach(function(item,index) {
tickets[index] = '#tribe-tickets__tickets-item-quantity-number--' + item;
});
// Add listener to the "Get tickets" button.
document.querySelector('#tribe-tickets__tickets-form #tribe-tickets__tickets-submit').addEventListener('click', function() { delaySetTwoStep(tickets); });
// Call function to adjust step to 2.
setTwoStep(tickets);
// Add delay for the modal
function delaySetTwoStep(tickets) {
// Need to wait for DOM to be generated
setTimeout(function() {setTwoStep(tickets); }, 200);
}
// Adjust step to 2.
function setTwoStep(tickets) {
var fields = document.querySelectorAll(tickets.join(', '));
fields.forEach(function (item, index) {
item.setAttribute('step', '2');
});
}
</script>
<?php
}
add_action( 'wp_footer', 'et_ticket_step_two' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment