Tickets for a single occurrence of an event

WordPress Event Management, Calendars & Registration Forums General Question Tickets for a single occurrence of an event

This topic contains 2 replies, has 2 voices, and was last updated by  Andrew Shankie 9 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #16189

    Hi Stephen and community,

    Apologies if something like this has been asked before, but if it has I couldn’t find it.

    I’m creating a repeating event (as Stephen has seen in a private email). If I go to /events/, I get a list of the individual occurrences, which is exactly what I want (especially once I customise the archive).

    What I’d like to happen, though, is when you click on one of those occurrences, you get a ticketing page for that particular occurrence, e.g. if I click on an occurrence due to occur on 15/05/2015, I get the opportunity to buy the ticket only for that occurrence. Currently, if I click on 15/05/2015, I get the post for the parent occurring event, with the ability to select the desired date using the jQuery date picker. This isn’t ideal as the user in my case would be expecting to buy tickets for 15/05/2015, not, for instance, the next available occurrence on 17/04/2015.

    Obviously I could write a template that hides the jQuery date picker and picks the appropriate date automatically for the user behind the scenes, but that seems a little hack-y. There’s probably a really obvious solution that I’m missing.

    Thanks!

    Andrew

    Andrew Shankie
    #16203

    Hi Andrew,

    If you append ?eventorganiser[booking][occurrence_id]={occurrence-id} to the end of the url it should automatically select that occurrence indicated.

    So, if you edit the page templates to modify the event url (returned by get_permalink()) then you can get the form to recognise which occurrence to select.

    That’s a bit ugly though, so we can improve things with an endpoint:

    add_action( 'init', 'my_register_endpoint', 15 );
    function my_register_endpoint(){
        add_rewrite_endpoint( 'occurrence', EP_PERMALINK ); 
    }
    

    You’ll need to flush the rewrite rules after this (just re-save your permalink settings). This allows use to use the url:

     mysite.com/events/event/my-event/occurrence/{occurrence-id}
    

    Next, we just need to tell the form:

    add_action( 'eventorganiser_get_event_booking_form', 'my_set_booking_form_occurrence_id', 10, 2 );
    function my_set_booking_form_occurrence_id( $form, $event_id ){
        global $wp_query;
        //Check if an occurrence is given
        if( $wp_query->get( 'occurrence' ) ){
           $occurrence_id =  (int) $wp_query->get( 'occurrence' );
           //Next, check that the booking form hasn't already been given an occurrence ID.
           if( !$form->get_element( 'occurrence_id' )->get_value() ){
              //If not, set the occurrence ID
              $form->get_element( 'occurrence_id' )->set_value( $occurrence_id );
           }
        }
     }
    

    And then as before, just update the page templates to append /occurrence/{occurrence-id}

    So rather than

     get_permalink();
    

    You might have

     get_permalink() . '/occurrence/' . $post->occurrence_id;
    

    There is a filter for the event calendar to change the link there too.


    The reason that this can only be done by editing the template is that the filters inside get_permalink() only pass the post ID, not the post object (which contains the occurrence ID). Therefore those filters are occurrence agnostic. I’d recommend creating the following function to replace get_permalink() for event links:

    function get_event_link(){
         global $post;
         $link = get_permalink();
         if( 'event' == get_post_type() && $post->occurrence_id ){
              $link = trailingslashit( $link ) . 'occurrence/' . intval( $post->occurrence_id );
         }
         return $link;
    }
    
    Stephen Harris
    #16209

    Hi Stephen,

    That’s really excellent. I haven’t had the chance to test the pretty permalinks code yet, but what you’ve suggested all makes perfect sense. I’ll incorporate it into my theme in the next couple of weeks and write back if I have any issues.

    At any rate, the query string solution works as a worst-case scenario, so I’m even quite happy with that.

    Thanks again for your support. Always first class!

    Andrew Shankie
Viewing 3 posts - 1 through 3 (of 3 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.