Created
March 8, 2024 11:55
-
-
Save andrasguseo/e8d704ce5de85b2ac4b05eb63e9873d9 to your computer and use it in GitHub Desktop.
ET > Set ticket limits based on event post ID.
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
<?php | |
/** | |
* Set ticket limits based on event post ID. | |
* | |
* Usage: | |
* - Add the snippet to your functions.php file or with a plugin like Code Snippets. | |
* | |
* @author Andras Guseo | |
* | |
* Plugins required: Event Tickets | |
* Created: March 8, 2024 | |
*/ | |
function et_my_custom_limits ( $limit, $ticket ) { | |
// Bail if there's no ticket provider. | |
if ( ! isset( $ticket->provider_class ) ) { | |
return $limit; | |
} | |
// Check which ticket provider is being used. | |
switch ( $ticket->provider_class ) { | |
case 'Tribe__Tickets__RSVP': | |
$metakey = '_tribe_rsvp_for_event'; | |
break; | |
case "Tribe__Tickets_Plus__Commerce__WooCommerce__Main": | |
$metakey = '_tribe_wooticket_for_event'; | |
break; | |
case 'TEC\Tickets\Commerce\Module': | |
$metakey = '_tec_tickets_commerce_event'; | |
break; | |
} | |
if ( ! isset( $metakey ) ) { | |
return $limit; | |
} | |
// Fetch the post ID. | |
$post_id = get_post_meta( $ticket->ID, $metakey, true ); | |
// Set limits based on post ID. | |
if ( $post_id == '804' ) { | |
$limit = 1; | |
} elseif ( $post_id == '866' ) { | |
$limit = 2; | |
} | |
return $limit; | |
} | |
add_filter( 'tribe_tickets_get_ticket_default_max_purchase', 'et_my_custom_limits', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment