Hello,
I need to make some booking forms accessible to members of my site and some accessible to the general public.
How do you recommend I add conditional logic to hide the form if the event is “members only”?
Thanks for any advice.

CYCOffice
Hi Louise,
You’ll want to make two changes. One to the booking form template (templates/eo-booking-form.php
) to hide the booking form. There is already logic in that template relating to whether a form should be displayed, so you can adapt it there. How to check whether the user is actually a member will depend on the membership plug-in you are using.
Secondly, as a ‘security’ measure, you’ll want to check when the booking form is being processed that the current user is not a member. While the booking form wouldn’t have been displayed a user could still making a booking with an appropriately crafted POST request.
To prevent this, just add the following code, adapted for your membership plug-in.
add_action( 'eventorganiser_validate_booking_form_submission', function( $form ) {
if ( /* user is not a member */ ) {
$form->add_error( 'members-only', 'You must be a member to place a booking' );
}
} );
I would recommend implementing this first, so that you can easily test it before hiding the booking form.

Stephen Harris
Thank you Stephen,
I can now see how I can hide the form.
How do you recommend I configure “member only” or “General Public” on an event by event basis. This needs to be something that a person creating a new event can set.
For example, is there a way to add a checkbox to the event setup box to select it as a “members only” event?

CYCOffice
Hi Louise,
You can get the event ID from the form as follows:
$event_id = $form->get( 'event_id' );
The event ID is the post ID (an event is of ‘event’ type). So you can do one of two things:
- Use a custom taxonomy (or even event tags / categories) as a way of marking an event as members only or not.
- Use a custom field (optionally you can create your own metabox).
Both 1 and 2 can be done with the standard WordPress API.

Stephen Harris
Thanks again,
I tried editing a child template version of eo-booking-form.php to add a test for if the Member Only category was set. but it never goes to the echo statement below.
I must be doing something wrong, sorry, but still feeling my way with php.
if ( !is_user_logged_in() && in_category('Member Only') ) {
echo "Member only event - login to make a booking";
}
else { //logged in or "public event"
//Display the booking form
?>
<form method="post" action="<?php echo get_permalink().'#eo-bookings';?>" id="eo-booking-form" autocomplete="off">
<?php
//Display custom fields
$this->display_form_fields();
?>
</form>

CYCOffice
in_category()
is for posts not events. You want:
is_object_in_term( get_the_ID(), 'event-category', 'Member Only' );

Stephen Harris