• Resolved moaschtr

    (@moaschtr)


    Hi everyone,

    I’m creating a custom single-event.php template. I’m not so good in php coding, so I hope somebody can point me in the right direction for basically getting the function of the conditional placeholders into the php template.
    The normal placeholders (e.g. #_BOOKINGFORM) work fine with the code snippet below, so I would need now a replacement for the {has_bookings}{/has_bookings}. I guess I have to insert some sort of if-statement, looking if booking for the event has been activated, but how? ?? Many thanks!!

    <?php global $post;
    $EM_Event = em_get_event($post->ID, 'post_id'); ?>
    
    {has_bookings}
    <div class="widget-wrapper">
    	<h3><?php echo __("Booking","my-child-theme"); ?></h3>
    	<?php echo $EM_Event->output("#_BOOKINGFORM"); ?>
    </div>
    {/has_bookings}
    • This topic was modified 5 years, 7 months ago by moaschtr.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    you can check the php file under events-manager/classes/em-event.php then search for function output() eg. has_bookings for conditional placeholders code

    Thread Starter moaschtr

    (@moaschtr)

    Thank you Angelo!
    That looks very good, I’m gonna try that out ??

    Thread Starter moaschtr

    (@moaschtr)

    @angelo_nwl , I found that code in the file em-event.php:

    if ($condition == 'has_bookings') {
    	//check if there's a booking, if not, remove this section of code.
    	$show_condition = ($this->event_rsvp && get_option('dbem_rsvp_enabled'));
    }

    but I’m not quite there yet… That’s my new code in the single-event template:

    if ($condition == 'has_bookings') {
    	echo '<div class="widget-wrapper">
    	<h3>' . __("Booking","my-child-theme") . '</h3>
    	' . $EM_Event->output("#_BOOKINGFORM") . '
    	</div>';
    };

    The form is not showing, I guess there is missing some line to access the output function variable $condition correctly, or what did I wrong?
    Many thanks once again!! ??

    No…
    The original code is what actually defines the {has_bookings} conditional placeholder. Meaning: “These are the arguments for this placeholder”. So changing that will change the actual meaning of {has_bookings} and frankly break the whole code.

    What Angelo meant, was look up the code that is processed when {has_bookings} is called and use that definition in your own code.

    if ($condition == 'has_bookings') {
    	//check if there's a booking, if not, remove this section of code.
    	$show_condition = ($this->event_rsvp && get_option('dbem_rsvp_enabled'));
    }

    Is to be read as:
    If the condition {has_bookings} is used, only show what is between the conditional placeholders, but ONLY show that part when:
    event_rsvp (checkbox “enable registrations for this event”) is checked AND “Allow Bookings” is set to “yes” in the EM Settings.

    So please do NOT change the original code, else {has_bookings} will not work anymore.

    In your own code you will need to use the same condition to achieve the same sort of output.

    global $post;
    $EM_Event = em_get_event($post->ID, 'post_id'); 
    if( $EM_Event->event_rsvp && get_option('dbem_rsvp_enabled') ) {
    	echo '<div class="widget-wrapper"><h3>' . __('Booking','events-manager') . '</h3>' . $EM_Event->output("#_BOOKINGFORM") . '</div>';
    }

    Personally, I think checking the EM settings is a bit redundant, as the checkbox can not be checked if bookings aren’t allowed. ??

    Or much more simplified:

    global $post;
    $EM_Event = em_get_event($post->ID, 'post_id'); 
    echo $EM_Event->output('{has_bookings}<div class="widget-wrapper"><h3>Booking</h3>#_BOOKINGFORM</div>{/has_bookings}');

    Using output() will let EM do all the work. Anything between () will be processed by EM. ??

    I use this last method myself for generating PDF’s andQR codes. And basically, that is what EM does as well with the Single Event Page markup…

    Thread Starter moaschtr

    (@moaschtr)

    @duisterdenhaag ok that’s the prove that I am not so good with php ??
    Thank you very much for your kind explanations, not only in my post but you are general so helpful around here!
    I first thought the {has_bookings}{/has_bookings} placeholders wouldn’t work in template files, but as they obviously do (with the right code ?? ) I will definitly follow your second suggestion and use the output() function ?? But it’s clearer now to me how the condition code behind it would have to look like!

    Personally, I think checking the EM settings is a bit redundant, as the checkbox can not be checked if bookings aren’t allowed. ??

    I did not quite understand what you mean by that…

    You are very welcome! Glad to help out. ??

    I did not quite understand what you mean by that…

    get_option('dbem_rsvp_enabled')
    Gets the saved value from the database. Option name ‘dbem_rsvp_enabed` is actually the radio button in Events > Settings > General > General Settings > Enable bookings?
    If set to yes, the meta box “Bookings/Registration” is. shown in the Single Event Edit Page. If set to no, that meta box is hidden and no tickets or bookings can be added to any event.

    Now, in that same meta box, the first checkbox is ‘event_rsvp’ -> “Enable registrations for this event”.

    So a logical way of thinking is that that checkbox can never be checked if you did not enable bookings globally using the radio button. If the radio button (get_option) is set to ‘no’, the checkbox ‘event_rsvp’ is always unchecked. So, checking both conditions seemed double to me. ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conditional placeholders in php template’ is closed to new replies.