Passing booking information to confirmation page

WordPress Event Management, Calendars & Registration Forums General Question Passing booking information to confirmation page

This topic contains 15 replies, has 2 voices, and was last updated by  Stephen Harris 9 years, 5 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #19151

    Hi Stephen,

    Another one here for you.

    In Pro, the feature to redirect the customer to a page is great, however, on that page, I’d like the ability to display some information about the booking they’ve just made. I’ve thought of and tried some options and not had any luck – could you help?

    Things I’ve thought about and tried:

    1. Put the booking ID into $GLOBALS so that the page template can access the booking id using something like:

    `function put_booking_into_globals($booking_id, $booking){
    $GLOBALS[‘eo_last_booking_id’] = $booking_id;</p>

    <p>}</p>

    <p>add_action( ‘eventorganiser_new_booking’, ‘put_booking_into_globals’, 5, 2);`

    This is pretty robust, but puts more guff into the global namespace

    1. Add a query string on the redirect in booking-actions.php around line 528 so that the page receives the booking id in a $_GET

    This works if I hack the plugin, but it’s obviously bad for that reason unless you plan on rolling in a feature. It also gives users a pretty easy way to see what else has been booked on the site

    1. On the page template, just query the bookings for the latest booking. This is bad as obviously there’s scope for error if two bookings happen at the same time

    Any other thoughts?

    Andrew Shankie
    #19154

    Hi Andrew,

    I think to do this you would either need to store a reference to the booking ID in a $_SESSION, or use WP_Session (see this plug-in) .

    In any case, it’s important not to allow the information displayed to be configured by something the user can control – as otherwise the user can manipulate that and see details of a booking which they have not made.

    Actually, even $_SESSION & WP_Session values can be manipulated but what is stored client side is a random ID which points to their session – which is not easily guessed or iterated through like a booking ID.

    This had been considered for core, however some hosts will not support $_SESSION (which is why WP_Session exists), however that’s a substantial library for a feature that’s not actually been requested until now.

    However, you should be able to implement this as a separate plug-in, (and I’d be able to help).

    On the gateway redirect hook you could store the booking ID as a $_SESSION or WP_Session. Then you can retrieve that value and display the information accordingly. This is essentially (1) but using $_SESSION rather than $_GLOBALS (so it survives across page loads – there is generally a redirect after a booking is created). You could use eventorganiser_new_booking but I would be tempted to use the gateway redirect in this instance, as the reason for storing the booking ID in the session data is specific to the ‘concrete’ process of on-site booking as opposed to the “abstract” hook ‘a booking has been created’.

    Stephen Harris
    #19167

    Hi Stephen,

    A session! Why didn’t I think of tha?. It’s been years since I’ve used sessions and they seem to have disappeared from my memory.

    A custom plugin sounds good – I’d like to do that as it would be a good opportunity to give something back to EO.

    I’ll get to work on it now and share something on Github. Just to confirm, I’ll probably create something with a pretty minimal interface (such as a single function along the lines of eo_get_customers_latest_booking()). Suggestions welcome on the function name!

    I was thinking about writing some other helpers to help people create their thank-you page template, but in the end I think it’s best if we return the $booking_id to the developer and let them sort out the rest. Instead of writing a bunch of wrappers around stuff that’s already there, I’ll provide some guidance in the readme about helpful functions that you could use to build up a confirmation page, such as:

    $ticket_quantity = eo_get_booking_meta($booking_id, 'ticket_quantity');
    $event_id = eo_get_booking_meta($booking_id, 'event_id');
    $occurrence_id = eo_get_booking_meta($booking_id, 'occurrence_id');
    eventorganiser_email_ticket_list($booking_id)
    etc etc.

    Cheers,

    Andrew

    Andrew Shankie
    #19170

    After reading Pippin Williamson’s blurb on WP_Session, I think I’ll do something similar and integrate WP_Session into my plugin, rather than relying on $_SESSION. I don’t see any reason not to at the moment and will get rid of a lot of complaints if running it on a shared host.

    Andrew Shankie
    #19173

    Stephen,

    Above you mention the gateway redirect hook as the place to do this. Can you tell me the specific name of the hook? I’ve got a couple ideas, but want to be sure.

    Cheers,

    Andrew

    Andrew Shankie
    #19190

    The idea of an extension sounds great :). Exposing an API sounds like the best way to go.

    You could provide a shortcode and template and have the template render the booking details. Developers could then just replace the template as desired.

    The hook I had in mind was: eventorganiser_pre_gateway_booking

    Stephen Harris
    #19202

    Hi Stephen,

    I’m hoping that I can call in that offer for help!

    I’ve got the basic mechanics of the session wrapper working (though it’s not working properly with WP_Sesssion at the moment as I’m having some header already sent grief, but that’s an issue to sort out later), but my main problem at the moment is the order that I’m hooking into things.

    Might be worth pulling my repo at https://github.com/shankiesan/eo-confirmation-page-session

    Let me explain the basic operation:

    1. Check if EO Pro is loaded
    2. Check which methods of session we can use. Because WP_Session isn’t working yet, instantiate an instance on the init hook using add_action('init', array ( Confirmation_Page_Session::get_instance(true), 'init' ), 5);, where the true forces us to use $_SESSION
    3. The class then checks whether we’re using $_SESSION or WP_Session and then hooks onto the eventorganiser_pre_gateway_booking using add_action( 'eventorganiser_pre_gateway_booking', array($this, 'set_booking_id')); – this method set_booking_id($args) takes the array sent and sets the session

    The class then provides a method so that in a template you could use Confirmation_Page_Session::get_instance()->get_booking_id() to return the booking ID.

    I’m fairly confident that my class is working well enough as I’ve got get_booking_id() returning some dummy content (just “not yet set” for now) if the session isn’t set. However, the session isn’t set! That’s because set_booking_id() doesn’t ever get called – and I can only assume that this is because I’ve screwed up my hook orders somewhere. I suspect it’s somewhere in between some stuff being on init and other stuff being on plugins_loaded.

    Any ideas?

    Apologies in advance for the slightly ropey coding to date. I’ll clean it up once bits start working!

    I’m a bit new to writing plugins like this… most of the stuff I’ve written so far has been pretty procedural…

    Cheers,

    Andrew

    • This reply was modified 9 years, 5 months ago by  Andrew Shankie. Reason: Correcting typos
    Andrew Shankie
    #19204

    Hi Andrew,

    Happy to take a look, but have you pushed the latest code – I’m seeing a blank page (other than the plug-in header) at https://github.com/shankiesan/eo-confirmation-page-session/blob/e7222e4ceed7d6ed315a4d2d7740e0f5deb9cc10/eo-confirmation-page-session.php

    Stephen Harris
    #19205

    Oops! That was careless of me. Try again…

    Andrew Shankie
    #19214

    I’ve realised “a problem but not the problem” – I had more hooks onto actions than I needed. The check if EO Pro happened on plugins loaded, which then added the init of the class onto init – which of course is redundant. It can just be done as soon as we’re sure that EO Pro has loaded.

    Committed and pushed, but not solved the problem!

    Andrew Shankie
    #19215

    As is usually the case with these things, explaining the problem to someone else forces you to think more critically about what’s going on.

    In order of solving:

    1. As above, unnecessary action hook
    2. The session wasn’t started using session_start(). Now conditionally starts the session if using PHP sessions in the init() method
    3. Changed the assignment of $_SESSION to $this->session to byref. Obvious!

    I’ve now got the booking ID available in my theme. Now it’s just about enabling some templating and shortcode, which should be pretty straightforward (and crucially easier to debug).

    Cheers,

    Andrew

    Andrew Shankie
    #19217

    I’ve added you as a collaborator on the project so that you can commit directly rather than having to faff around with pull requests.

    A special thanks to London Elektricity at Hospital Records for providing Hospital Podcast 275 – excellent listening material!

    Andrew Shankie
    #19225

    Ok Stephen, I’ve now got a skeleton working nicely! It needs some tidying up, and most importantly documentation, but it works well enough at the moment to go live on my client’s site.

    Feel free to either make suggestions on how it should be refactored, or of course, pull the repo and get stuck in yourself.

    Cheers,

    Andrew

    Andrew Shankie
    #19239

    Hi Andrew,

    It sounds like you’ve made a lot of progress in a day, I’m just about to checkout a copy of the plug-in and will give it a whirl.

    Stephen Harris
    #19262

    Hi Stephen,

    Glad the plugin was working for you. Seems to be working pretty nicely for me now too.

    If you get the chance, do you want to see if you can integrate WP_Session? I was having some troubles with cookies being set once headers were being sent. I’m happy to spend more time on this, but just need to get some client work out the door over the next few days…

    Will also write some documentation for the thing!

    Cheers,

    Andrew

    Andrew Shankie
Viewing 15 posts - 1 through 15 (of 16 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.