I am using a plugin called WP events manager, I would like to add custom functionality so that each event can be 'added' to a 'basket' then at the end the user can go the the 'checkout' and register for these events.

I believe this is done by storing the ID of the event when the user clicks add in PHP sessions and then looping though the items at the check out with the infomation you enter at the check out.

I am new to PHP sessions and not sure how I can store an ID on click of a button, and then loop through them at the end, if anyone knows about this, or knows any related articles I would be very grateful, googling the subject sent me into a mine field.



1 Answer 1


It is relatively simple. I've giving you a few steps.

User visits your site and hit 'Add to basket' on an event. You need to send this data to server (as you wanted to store in php session). you can submit a form (for simplicity) either in synchronously or asynchronously (ajax). You need to submit a form to your URL where it stores (temporary/permanent) the order info to your system. For example, your 'addtobasket.php' handles the orders. so the form may be like:

<form action="/addtobasket.php" method="post">
<input type="hidden" name="event_id" value="101" />
<input type="submit" name="Add to Basket" />

the addtobasket.php now stores the order in the session using the following code:

$_SESSION['event_orders'][] = $_POST['event_id'];

after storing the data in session, you should redirect user where you want (probably where he/she was). in the checkout page (for example checkout.php) you can get all the events id that was ordered (added to basket).

foreach($_SESSION['event_orders'] AS $event_id){
echo 'Your ordered event ID is: ' .$event_id;

In the 4th line, you will get event ID. now you can fetch the event details from your storage and show event information and do the rest of the steps.

however, the above codes are the bare minimum codes. in your implementation, you will need lots of other codes including data sanitization.

The following link is quite old but surely can give you some idea: http://v3.thewatchmakerproject.com/journal/276/

More about php session: http://au.php.net/manual/en/session.examples.basic.php http://www.phpriot.com/articles/intro-php-sessions

you can also store order info on the client side (cookie, html5 session storage) until user decides to checkout. during checkout you can send the data to server and store them.

  • Wow, thanks for all this, I will take a good read of this shortly and get back to you! Commented Jun 20, 2012 at 17:07
  • This does what I originally asked, tho it has opened more questions for me, but thanks! Commented Jun 21, 2012 at 10:34
  • questions are the basic ingredient for learning. keep researching and asking :). Commented Jun 21, 2012 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.