Conditional Attendee Questions
WordPress Event Management, Calendars & Registration › Forums › General Question › Conditional Attendee Questions
This topic contains 11 replies, has 3 voices, and was last updated by Greg MacKinnon 9 years ago.
-
AuthorPosts
-
February 10, 2016 at 4:48 pm #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
February 11, 2016 at 1:16 pm #21337Hi 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
February 11, 2016 at 9:00 pm #21343Terrific. 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
February 15, 2016 at 4:17 pm #21400Stephen,
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 thanksAlex Steer
February 16, 2016 at 4:09 pm #21408Hi 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
February 16, 2016 at 9:30 pm #21424Thank 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
March 1, 2016 at 10:08 am #21666Hi 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’?
ThanksAlex Steer
March 1, 2016 at 11:17 am #21669I 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
March 1, 2016 at 12:39 pm #21670Can 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
March 1, 2016 at 2:11 pm #21675Ok, 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
March 1, 2016 at 9:35 pm #21690Yes, 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
March 1, 2016 at 10:27 pm #21692For 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
-
This reply was modified 9 years ago by
-
AuthorPosts