Conditional Attendee Questions

This topic contains 11 replies, has 3 voices, and was last updated by  Greg MacKinnon 9 years ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #21319

    Is it possible to have Attendee Questions come up only for certain event types?

    For example, similar to defining a custom field for gateways, can a custom field be defined that identifies the event type and that determines whether the Attendee Questions come up?

    Thanks.

    Greg MacKinnon
    #21337

    Hi Greg,

    I assume you’re following this post: http://wp-event-organiser.com/blog/tutorial/attendee-questions/

    The fields which are added get defined here:

    function my_attach_attendee_questions( $form ){
    
        //Define the field we want to add    
        $attendee_fields = array(
            array(
                'id'   => 'attendee-name',
                'type' => 'name',
                'required' => true,
            ),
           //.. other fields here ...
        );
         //...
    }
    

    So you can decide, changing how $attendee_fields is defined whether to add fields, or what fields to add, for a particular event, or event category. You can get this information from the $form instance as follows:

    $event_id = $form->get( 'event_id' ); //event ID
    $event_cats = get_the_terms( $event_id, 'event-category' ); //array of event category objects
    
    Stephen Harris
    #21343

    Terrific. Thank you.

    Yes, I had successfully implemented the items from the tutorial you referenced, but then I realized that it was universal and the nature of my events (at least the questions) changed.

    I can now apply conditions to determine the questions to be displayed, if any.

    Greg MacKinnon
    #21400

    Stephen,
    I was looking at this post and I found it interesting…
    How this be modified so attendee questions we linked to a specific form id in the admin?
    Could it be as simple as replacing $form with the form id?
    Many thanks

    Alex Steer
    #21408

    Hi Alex,

    No but you can get the form ID from $form->id and add elements (or not) based on that.

    Better yet, you can use $form->get( 'name' ) to get the (human given) name of the form to identify it. That way if you delete the form and create a new one, you won’t need to update your code – simply give it the appropriate name.

    Stephen Harris
    #21424

    Thank you. I like this better.

    I have a different registration form for each type of event anyway.

    I found this much easier to implement.

    Greg MacKinnon
    #21666

    Hi I’m wanting to make my attendee questions condition based upon: $form->get( ‘name’ ) as discussed.
    I will have two events let’s say ‘event-a’ and ‘event-b’ and both will have seperate booking forms.
    I know that I can make the questions conditional but how do I make sure the associated actions & filters are conditional to only work with the intended attendee questions?

    function my_attach_attendee_questions( $form->get( 'event-a' ) ){ 
    Code here
    add_action( 'eventorganiser_get_event_booking_form', 'my_attach_attendee_questions', 5 );
    
    add_filter( 'eventorganiser_export_tickets_headers', function( $columns ) {
    Code here
    }, 10, 3 );
    
    add_filter( 'eventorganiser_booking_tickets_table', function( $columns ){
    Code here
    });
    
    add_action( 'eventorganiser_booking_tickets_table_column', function( $column_name, $item ){
    Code here
    },10,2);
    
    add_filter( 'eventorganiser_email_ticket_list', function( $booking_table, $booking_tickets, $booking_id, $template ) {
    Code here
    }, 10, 4 );
    
    add_filter( 'eventorganiser_notify_confirmed_booking', function( $send_default_email, $booking_id ) {
    Code here
    }, 10, 2 );
    

    Is there a way to make them work let’s say within the ‘event-a’ function so I could create another set for ‘event-b’?
    Thanks

    Alex Steer
    #21669

    I have been thinking about this some more… I suspect the only changes I need to make are in the CSV output and the Admin columns generatio script. The emails won’t be effected as the same info is used for both event regarding those.

    ‘event-a’ and ‘event-b will have the same amount of attendee questions although one will be different in context.

    Can I get the admin attendee questions ticket columns to only show if they have data (it may be setup that way already, please comment)? – Not sure if this will appy to the CSV too.

    Alex Steer
    #21670

    Can I get the admin attendee questions ticket columns to only show if they have data (it may be setup that way already, please comment)

    In general its not possible to know in advance if a column will have any values, it creates these on the fly. This is further complicated by the fact that a CSV export could include tickets from either event, and so require the columns for each.

    On thing you could do is merge the columns: define a common header and then for the cell callback determine which event the ticket is associated with (if required). Just in case, for example, you are using a different element ID.

    add_filter( 'eventorganiser_export_tickets_cell', function( $cell, $column, $ticket ) {
        //How to get the event ID from a given $ticket object. 
        $booking_id = $ticket->booking_id; //Booking ID
        $event_id   = eo_get_booking_meta( $booking_id, 'event_id' ); //Event ID
    
         //For the appropriate value of $column return the cell content
         //which can be based on the $event_id above.
    
    }, 10, 3 );
    

    Incidentally – you can use the same element ID on different booking forms, it only has to be unique within that form. So, for example, if you have different meal choices for event A and event B, just add an element with ID ‘meal_choice’ and switch the ‘options’ parameter based on the options available for that event.

    Stephen Harris
    #21675

    Ok, I see what you mean… The CSV is not so much a problem as the cells could just be empty – the data is better seperated on this for working with formulas in excel.

    So, if I had a generic column name title in the admin could the data be switched like below?:

      $detailsa = eo_get_booking_ticket_meta( $ticket->booking_ticket_id, '_eo_booking_meta_attendee-title', true );
    $detailsb = eo_get_booking_ticket_meta( $ticket->booking_ticket_id, '_eo_booking_meta_attendee-ticket', true );
    switch( $column ){
    case 'ticket_admin_column': 
    if ($detailsa != '') {
    return $detailsa;
    } elseif ($detailsb != '') {
        return $detailsa;
    } else { 
    }
    break;
    }, 10, 3 );
    
    • This reply was modified 9 years ago by  Alex Steer.
    Alex Steer
    #21690

    Yes, but instead of trying to retrieve $detailsa and $detailsb and seeing which is empty, you could compare the event ID (as shown in my previous reply), which is a little more robust.

    As an aside, I would also switch the retrieving of data to inside the switch statements (under the appropriate case). As it stands you’re retrieving $detailsa and $detailsb for all cells, rather than just the one where it is required. Granted, this data is cached by WordPress, but if I recall correctly if the meta key doesn’t exist (e.g. $detailsb for a booking for Event A) then it hits the database each time.

    Stephen Harris
    #21692

    For what it’s worth, I implemented generally as described above.

    I have a conditional statement for each booking template. In this way, I am able to ask a different set of questions for each event type.

    I modified my CSV output to include a column for every question. Of course, there is a lot of overlap (i.e. every template asks for name, organization and e-mail), but there are some unique questions as well (i.e. meal choice versus events with no meals). The resulting output includes values where there are values and blanks where there are none, which is just what I need.

    I elected to make no changes to the Admin table because I found that too much information on that page was crowded. The CSV ticket output is now exactly the information needed at the door. I simply filter for the event and then download the tickets for the person at the door to use as a checklist.

    Greg MacKinnon
Viewing 12 posts - 1 through 12 (of 12 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.