Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active November 2, 2020 17:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cliffordp/80b33455779b74ec49f6ea3033cb47bf to your computer and use it in GitHub Desktop.
Save cliffordp/80b33455779b74ec49f6ea3033cb47bf to your computer and use it in GitHub Desktop.
Set default quantity of 1 and READONLY for all tickets: Same as https://gist.github.com/cliffordp/5b57df71be8b52f595817ddbf81acdab except make quantity readonly
<?php
/**
* Set default quantity of 1 and READONLY for all tickets:
* - Event Tickets RSVP
* - Event Tickets Plus WooCommerce
* - Event Tickets Plus Easy Digital Downloads
*
* From https://gist.github.com/cliffordp/80b33455779b74ec49f6ea3033cb47bf
*
* Same as https://gist.github.com/cliffordp/5b57df71be8b52f595817ddbf81acdab except make quantity readonly
* Watch out if you have more than 1 ticket per event!
*
* ! You may want to use https://gist.github.com/cliffordp/9a457b724e38b3036f8d48adc90930ed instead!
*/
function cliff_all_tickets_default_quantity_and_readonly() {
// bail if not on a Single Event page
if ( ! function_exists( 'tribe_is_event' ) || ! tribe_is_event() ) {
return false;
}
wp_enqueue_script( 'jquery' );
?>
<script type="text/javascript">
jQuery(document).ready( function () {
// RSVP, Woo, and EDD tickets default to quantity of 1
jQuery( 'input.tribe-ticket-quantity, .woocommerce .quantity input.qty, .edd.quantity input.edd-input' ).val( 1 ).attr( 'readonly', true );
// CSS to display RSVP tickets' "Send RSVP confirmation to" fields
// Note: will continue to show even if user changes quantity to zero because we didn't bind to the field to continually watch it
jQuery( 'tr.tribe-tickets-meta-row' ).show();
});
</script>
<?php
}
add_action( 'wp_footer', 'cliff_all_tickets_default_quantity_and_readonly' );
@daliakopoulos
Copy link

for single ticket per event you can change the script part to:

<script type="text/javascript"> jQuery(document).ready( function () { //when field changes jQuery('input.tribe-ticket-quantity').on('keyup', function() { var changedField = this; jQuery('input.tribe-ticket-quantity').each(function(){ //change all fields to 0 this.value=0; }); // and set changed field to 1 changedField.value = 1; }); }); </script>

@cliffordp
Copy link
Author

@daliakopoulos, you can change it however you like to customize it further. If you're needing additional support for this snippet or are reporting it broken, please contact Event Tickets Plus support at https://support.theeventscalendar.com/submit_ticket

@skyshab
Copy link

skyshab commented Nov 2, 2020

input.tribe-ticket-quantity should be input.tribe-tickets-quantity. not sure if this was a change in the class name on the field, or a typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment