I recently bought your pro plugin. It’s awesome and maybe one of the best if not the best event organising or managing plugin for wordpress.
I read already through http://wp-event-organiser.com/forums/topic/pre-defined-ticket-applied-to-a-new-event/.
How do I insert pre-defined tickets for each occurrence of one event automatically upon saving the event? Is there a way to accomplish that?
Thanks, beo

B+eo
HI beo,
Do you mean pre-defined ticket available for all occurrences, or each occurrence has it’s own pre-defined ticket (different from other occurrences)?

Stephen Harris
All occurrences of one event should have the same pre-defined ticket. The tickets don’t differ between multiple occurrences of one event.

B+eo
I see, well that thread I think covers everything. The first snippet gives an example of how to create a default ticket. Further down there is one to set the occurrences of each of the tickets.
It would be possible to store a ‘flag’ containing the default ticket ID, so that second snippet only runs once per event, and only for the “default” ticket. But even then, the first time it will over-ride the user’s selection of dates.
Unfortunately it’ s not possible to create a default ticket for all occurrences, because the occurrences are not yet known (or might, in any case, change).
A better method might be, to use the snippet in the linked thread, and then if any tickets has no dates associated to it you assume that the user hasn’t specifically selected any dates, and so set the occurrences to all. This would work well if you think there is no good reason why a user would want to create a ticket but not have any dates associated to it.
The following snippet is adapted from the linked to thread and does what I describe above:
add_action( 'eventorganiser_save_event', 'my_update_default_tickets', 20 );
function my_update_default_tickets( $event_id ){
$occurrences = eo_get_the_occurrences_of( $event_id );
$occurrence_ids = array_keys( $occurrences );
$tickets = eo_get_event_tickets( $event_id );
foreach( $tickets as $ticket_id => $ticket ){
if( empty( $ticket['occurrence_ids'] ) ){
$ticket['occurrence_ids'] = $occurrence_ids;
}
eventorganiser_update_ticket( $ticket_id, $ticket );
}
}

Stephen Harris
Actually the other thread really covered everything. Thank you very much for the explanation and for the snippet. I adapted it and it’s working wonderfully.
I’m still new to the whole wordpress-php-development thing, so I have to read that code three times until I understand … 🙂

B+eo