Posted: 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('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(){ $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($fname, 0, 4) .'+'. substr($lname, 0, 4) . substr($id, 0, 3); return $id; } add_filter('filter_hook_espresso_registration_id', 'my_custom_registration_id', 10, 1);</code>
|
|
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. |
|
How would I modify my existing code to work with the updated data? |
|
I have already updated add_attendees_to_db with your hot fix. |
|
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); |
|
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. |
|
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. |
|
Thanks for the help Dean. I re-did all the steps and its working now. Cheers |
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.