Support

Home Forums Event Espresso Premium Custom Registration ID (2)

Custom Registration ID (2)

Posted: June 2, 2014 at 4:43 am

Viewing 7 reply threads


Baadier Sydow

June 2, 2014 at 4:43 am

Hi,

I was following the steps included on this post https://eventespresso.com/topic/custom-registration-id/ but I cant seem to figure out how to pull the attendees First Name and Last Name to create a registration ID that takes takes the first 3 characters of each and combines them along with the id.

This is what I have:

<code>// remove default registration id filter
function my_remove_registration_id_filter() {
  remove_filter(&#039;filter_hook_espresso_registration_id&#039;, &#039;espresso_build_registration_id&#039;, 10);
}
add_filter (&#039;filter_hook_espresso_registration_id&#039;, &#039;my_remove_registration_id_filter&#039;, 9 );

function my_custom_registration_id(){
  $id = uniqid();
  // for the sake of an example, we&#039;ll convert the unique ID to be letters from the alphabet, which would make for something similar to an airline&#039;s reservation code
  $id = substr($fname, 0, 4) .&#039;+&#039;. substr($lname, 0, 4) . substr($id, 0, 3);
  return $id;
}

add_filter(&#039;filter_hook_espresso_registration_id&#039;, &#039;my_custom_registration_id&#039;, 10, 1);</code>
  • This topic was modified 10 years, 5 months ago by Baadier Sydow.
  • This topic was modified 4 years, 8 months ago by Garth.


Dean

June 2, 2014 at 5:52 am

Hi,

The problem is that the filter is only being passed one variable, the event ID. As such your function does not know the users name so cannot use it in the new registration ID.

The only way to get it to do what you want would be to edit the core file and modify the filter to accept more data.

I will raise a ticket to see if we can edit it in future versions (no guarantee) to send the $data_source array instead of just the event ID. That way you will have access to more information.

If you did want to modify the core file, then thats what I would do, edit the /wp-content/plugins/event-espresso/includes/process-registration/add_attendees_to_db.php file and on line 301 change the filter from this

$registration_id = empty($wpdb->last_result[0]->registration_id) ? apply_filters('filter_hook_espresso_registration_id', $event_id) : $wpdb->last_result[0]->registration_id;

to this

$registration_id = empty($wpdb->last_result[0]->registration_id) ? apply_filters('filter_hook_espresso_registration_id', $data_source) : $wpdb->last_result[0]->registration_id;

Then your function will have access to an array of the users data including names.


Baadier Sydow

June 2, 2014 at 6:22 am

How would I modify my existing code to work with the updated data?


Baadier Sydow

June 2, 2014 at 6:22 am

I have already updated add_attendees_to_db with your hot fix.


Dean

June 2, 2014 at 6:43 am

Something like this

remove_filter('filter_hook_espresso_registration_id', 'espresso_build_registration_id', 10);

function my_custom_registration_id($x){

// debugging stuff remove if you dont need it
//var_dump($x);
//echo "<br>";
//wp_die();

$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
$id = substr($x['fname'], 0, 4) .'+'. substr($x['lname'], 0, 4) . substr($x['event_id'], 0, 3);
return $id;
}

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


Baadier Sydow

June 2, 2014 at 7:22 am

I could be having a stupid day but it doesn’t seem to be working. I tried doing print_r($x) and var_dump($x) on the variable and nothing shows up. I turned on debugging on too in wp-config.

Only the “+” is displayed.


Dean

June 3, 2014 at 1:41 am

Hi,

I double checked and this is working for me http://take.ms/ns7Gm

Just to clarify:

The add_attendees_to_db was modified? Without that the data will not be there to show.
You are using EE3?
You have added the code to your themes functions.php file?


Baadier Sydow

June 6, 2014 at 9:22 am

Thanks for the help Dean. I re-did all the steps and its working now.

Cheers

Viewing 7 reply threads

The support post ‘Custom Registration ID (2)’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso