Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    you can try to hook into javascript em_booking_success

    eg.

    
    jQuery(document).bind('em_booking_success', function() {
            window.location.href = "https://google.com";
    });
    
    
    Thread Starter KS

    (@karl19)

    Thanks a lot for the reply! I added the following code to functions.php:

    function event_form_redirection(){ ?>
        <script type="text/javascript">
        jQuery(document).ready( function($){
            jQuery(document).bind('em_booking_success', function() {
                window.location.href = "https://www.mywebsite.com/thank-you/";
            });
        });
        </script>
    <?php };
    add_action('wp_head', 'event_form_redirection');

    and it redirects fine. What I can’t figure out is how to only show this code snippet on EM event pages. When searching, I found a lot of shortcodes, but no template conditionals? Would you have any tips for the code above, to make it only show on event pages?

    You shouldn’t load that in the header, because often jQuery is not loaded yet and you will get errors. Also, you could use the WP native conditional is_singular(‘event’);, but that will never work in the header, because then WordPress had no time to initialise the page yet. See: https://codex.www.ads-software.com/Function_Reference/is_singular

    So you could wrap your conditional action in a function that is enqueued later.

    But because you only need this, not just in an event page, but only in an event page with bookings enabled, I would suggest hooking directly into the booking form. No booking form? No script added. ??

    Change your add_action() to:
    add_action('em_booking_form_footer', 'event_form_redirection', 20);

    Thread Starter KS

    (@karl19)

    Many, many thanks for this Patrick, exactly what I was looking for! That it perhaps shouldn’t have gone in the header I should have thought of, but that add_action (em_booking_form_footer) I hadn’t managed to find. Thanks a lot for your input, have a nice day!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Redirect on success’ is closed to new replies.