Skip to content

Instantly share code, notes, and snippets.

@chikaibeneme
Created February 28, 2025 07:03
Show Gist options
  • Select an option

  • Save chikaibeneme/56a93e181e89963126936dc4e8037795 to your computer and use it in GitHub Desktop.

Select an option

Save chikaibeneme/56a93e181e89963126936dc4e8037795 to your computer and use it in GitHub Desktop.
require tickets.php
// Add the custom 'has_tickets' field to the list of required fields
add_filter( 'tribe_events_community_required_fields', function( $fields ) {
// Add our custom field identifier to the required fields array
$fields[] = 'has_tickets';
return $fields;
} );
// Validate the 'has_tickets' field during event submission
add_filter( 'tribe_community_events_validate_submission', function( $valid, $event_id, $args ) {
// Check if the current user is an admin; if so, skip validation
if ( current_user_can( 'manage_options' ) ) {
return $valid;
}
// Check if the 'has_tickets' field is in the required fields and being validated
if ( in_array( 'has_tickets', $args['required_fields'] ) ) {
// Verify if the event has tickets
if ( ! function_exists( 'tribe_events_has_tickets' ) || ! tribe_events_has_tickets( $event_id ) ) {
// Add an error message to the form errors
$args['form']->add_error( 'has_tickets', __( 'Please add at least one ticket to the event.', 'your-text-domain' ) );
// Invalidate the submission
$valid = false;
}
}
return $valid;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment