Skip to content

Instantly share code, notes, and snippets.

@cliffordp cliffordp/functions.php
Last active Dec 16, 2018

Embed
What would you like to do?
Event Tickets: Set the maximum quantity allowed per ticket.
<?php
/**
* Event Tickets: Set the maximum quantity allowed per ticket.
*
* !!! Change the maximum to your own !!! Needs to be higher than priority 10 because of
* Tribe__Tickets_Plus__Commerce__WooCommerce__Main::filter_ticket_max_purchase()
* Does not work for unlimited stock WooCommerce Tickets until https://central.tri.be/issues/119822 is fixed.
*
* @param int $available Max Purchase number
* @param Tribe__Tickets__Ticket_Object $ticket Ticket Object
* @param int $event_id Event ID
* @param int $ticket_id Ticket Raw ID
*
* @link https://gist.github.com/cliffordp/61cd8374a80d1b2bc76a6650e9304a63 This snippet.
*/
function event_tickets_max_qty( $available, $ticket, $event_id, $ticket_id ) {
// TODO: Change this to what you want!!!
$max_qty = 4;
$allowed = min( $max_qty, $available );
if ( -1 === $allowed ) {
// Account for unlimited quantity
$allowed = $max_qty;
}
return $allowed;
}
add_filter( 'tribe_tickets_get_ticket_max_purchase', 'event_tickets_max_qty', 50, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.