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.
-
AuthorPosts
-
September 25, 2015 at 2:39 pm #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:
- 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
- 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
- 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
September 26, 2015 at 12:22 pm #19154Hi Andrew,
I think to do this you would either need to store a reference to the booking ID in a
$_SESSION
, or useWP_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 whyWP_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
orWP_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 useeventorganiser_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
September 28, 2015 at 9:27 am #19167Hi 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');
etc etc.
$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)Cheers,
Andrew
Andrew Shankie
September 28, 2015 at 9:32 am #19170After 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
September 28, 2015 at 12:00 pm #19173Stephen,
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
September 28, 2015 at 5:36 pm #19190The 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
September 29, 2015 at 7:22 pm #19202Hi 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:
- Check if EO Pro is loaded
- Check which methods of session we can use. Because WP_Session isn’t working yet, instantiate an instance on the
init
hook usingadd_action('init', array ( Confirmation_Page_Session::get_instance(true), 'init' ), 5);
, where thetrue
forces us to use$_SESSION
- The class then checks whether we’re using $_SESSION or WP_Session and then hooks onto the
eventorganiser_pre_gateway_booking
usingadd_action( 'eventorganiser_pre_gateway_booking', array($this, 'set_booking_id'));
– this methodset_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 becauseset_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 oninit
and other stuff being onplugins_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
September 29, 2015 at 7:41 pm #19204Hi 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
September 29, 2015 at 8:30 pm #19205Oops! That was careless of me. Try again…
Andrew Shankie
September 30, 2015 at 9:42 am #19214I’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
September 30, 2015 at 11:12 am #19215As 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:
- As above, unnecessary action hook
- The session wasn’t started using
session_start()
. Now conditionally starts the session if using PHP sessions in theinit()
method - Changed the assignment of
$_SESSION
to$this->session
tobyref
. 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
September 30, 2015 at 11:23 am #19217I’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
September 30, 2015 at 12:34 pm #19225Ok 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
September 30, 2015 at 10:19 pm #19239Hi 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
October 1, 2015 at 9:21 am #19262Hi 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
- Put the booking ID into
-
AuthorPosts