Publish occurrences / tickets programmatically

WordPress Event Management, Calendars & Registration Forums General Question Publish occurrences / tickets programmatically

This topic contains 7 replies, has 2 voices, and was last updated by  Benjamin Ogg 3 years, 7 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #38448

    Dear Stephen

    Would it be possible to publish occurrences (in connection with their tickets) programmatically for event recurrence?

    For example: Publish all occurrences of the following week on Sunday evening?

    Thanks for looking into this.

    Cheers, Benjamin.

    Benjamin Ogg
    #38472

    Hi Benjamin,

    You can’t publish an occurrences independently of the event. It should be possible to make bookings available only for occurrences in the coming week, however (albeit not through the UI) – is that what you’re trying to achieve?

    Stephen Harris
    #38488

    Hi Stephen

    Thanks for your answer and sorry for not being enough specific.
    Lets say there is a yoga class every Monday at 9am. On every Sunday the occurrence can be viewed in the calendar and the booking for this occurrence is possible.
    Would you execute this code as a paid job?
    Happy Sunday, Benjamin

    Benjamin Ogg
    #38496

    Hi Benjamin,

    So the most straightforward way would be to create the event’s full occurrences and then hide occurrences that are more than X days away. Alternatively you could display the dates, but the make it unbookable until with X days.

    Here’s how to do the former:

    add_filter('pre_get_posts', function($query){
        if( ! eventorganiser_is_event_query( $query, true ) ) {
            return $query;
        }
        if (is_admin()) {
            return $query;
        }
    
        if (!$query->get( 'event_start_before')){
            $next_week = new DateTime( '+6 days', eo_get_blog_timezone() );
            $query->set( 'event_start_before', $next_week->format('Y-m-d') );
        }
    }, 13);
    

    Though currently it will still appear on the calendar. If your users will be logged-out you could do

    if (is_admin() && !is_user_logged_in()) {
        return $query;
    }
    

    Then it will be visible to users logged-in, but not to logged-out customers on the calendar.

    To make just some occurrences bookable (but still dates still visible on calendars and lists), you can instead do:

    add_filter( 'eventorganiser_bookable_occurrences', function( $bookable, $event_id ) {
        $next_week = new DateTime( '+6 days', eo_get_blog_timezone() );
        foreach( $bookable as $occurrence_id => $occurrence ) {
            if ( $next_week > $occurrence['start'] ) {
                unset( $bookable[$occurrence_id] );
            }
        }
        return $occurrences;
    }, 10, 2 );
    
    Stephen Harris
    #38513

    Thanks for your support, Stephen. I highly appreciate this.
    I will test your code and will let you know, how’s it going.
    Cheers, Benjamin.

    Benjamin Ogg
    #38527

    Dear Stephen
    Please allow another question:
    I am using shortcodes to display events [eo_fullcalender] and booking form [event_booking_form]
    How can I integrate your code there accordingly?
    Sorry, I am not that good in code… :o(
    Cheers, Benjamin

    Benjamin Ogg
    #38585

    Hi Benjamin,

    Unfortunately that’s the limitation I referred to. It’ll still appear on the calendar, but you could hide them from non-logged-in users:

    add_filter('pre_get_posts', function($query){
        if( ! eventorganiser_is_event_query( $query, true ) ) {
            return $query;
        }
        if (is_admin() && !is_user_logged_in()) {
            return $query;
        }
    
        if (!$query->get( 'event_start_before')){
            $next_week = new DateTime( '+6 days', eo_get_blog_timezone() );
            $query->set( 'event_start_before', $next_week->format('Y-m-d') );
        }
    }, 13)
    

    See this page on where to add the code: https://wp-event-organiser.com/blog/tutorial/where-should-i-put-code-from-the-tutorials/

    Note, the calendar is cached so after making any code changes you may need to update an event to see any change.

    Stephen Harris
    #38601

    Thanks a lot for your effort, Stephen.
    I appreciate it a lot.

    Benjamin Ogg
Viewing 8 posts - 1 through 8 (of 8 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.