How to Create a Custom Registration ID

This guide is for Event Espresso version 3.

The attendee registration ID is used throughout Event Espresso 3 to find, and display a particular attendee. It is used in the admin, the emails and the tickets (with the Ticketing Add On).

The registration ID does have some meaning but in practical use it is merely a set of random and unique letters and numbers.

If you want to make the registration ID more useful, here’s how you can do it.

Add the following code to your themes functions.php or preferably a custom_functions.php file in wp-content/uploads/espresso.

function my_remove_registration_id_filter() {
  remove_filter('filter_hook_espresso_registration_id', 'espresso_build_registration_id', 10);
}
add_filter ('filter_hook_espresso_registration_id', 'my_remove_registration_id_filter', 9 );


function my_custom_registration_id(){

	$date = date('Y-m-d');
	$count = $_POST['num_people'];
	$cost = $_POST['event_cost'];

	$id = $date . '-' . $count . '-' . $cost . '-' . rand(100, 1000);
  
	return $id;
}

add_filter('filter_hook_espresso_registration_id', 'my_custom_registration_id', 10, 1);

Let’s break this down:

This will remove the existing code that creates the registration id

function my_remove_registration_id_filter() {
  remove_filter('filter_hook_espresso_registration_id', 'espresso_build_registration_id', 10);
}
add_filter ('filter_hook_espresso_registration_id', 'my_remove_registration_id_filter', 9 );

This function is what creates the new registration ID.

function my_custom_registration_id(){
     $id = uniqid();
     // for the sake of an example, we'll convert the unique ID to be letters from the alphabet, which would make for something similar to an airline's reservation code
     return strtr($id, '01234567890', 'abcdefghij');
}

This will apply our new function

add_filter('filter_hook_espresso_registration_id', 'my_custom_registration_id', 10, 1);

That function will basically just change the already random ID into a slightly more structured but still random ID.

What if you wanted to add in more useful information such as the event cost?

That’s where the $_POST variable come in. This variable contains information from the event. Most of the time the following is available (but this can differ from event to event):

  • event_cost (if the event has a price)
  • payment (if the event is free)
  • start_time_id
  • fname
  • lname
  • email
  • use_coupon
  • use_groupon
  • event_id
  • num_people

Note that if you use event_cost in the ID but the event is free nothing will print out, so it is advisable to do a check for to see if the event_cost exists or not.

Here is an example that creates an ID with the date, number of tickets and event cost. Instead of creating just a random string it uses actual data to build the registration ID:

function my_custom_registration_id(){

	//get todays date
	$date = date('Y-m-d');

	//how many tickets were there?
	$count = $_POST['num_people'];

	//if there is more than one attendee, this will check the amount
	if(!isset($count)) { $count = count($_POST['x_attendee_fname']) + 1; }

	//how much did the event cost?
	$cost = $_POST['event_cost'];

	//lets make sure there is a cost, otherwise lets use the word free instead
	if(!isset($cost)) { $cost = "free"; }

	//combine them all up, seprated by dashes and add some random numbers at the end.
	$id = $date . '-' . $count . '-' . $cost . '-' . rand(1000, 100000);
  
	return $id;
}

For an event registered on the 5th June 2014 for 1 person, at a cost of $20.00, the registration id would be:

2014-06-05-1-20.00-5874

The last digits are random, just to help keep things unique.

This has been tested on standard registrations and Multiple Event Registration (MER) cart registrations and works, with the exception that it is very difficult to get the ticket count to work as each attendee is registered separately with MER.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us