Support

Home Forums Event Espresso Premium Get all related user id's when tickets are purchased.

Get all related user id's when tickets are purchased.

Posted: April 3, 2017 at 1:04 pm


SMills

April 3, 2017 at 1:04 pm

When tickets are purchased for one or more attendees, I need to run custom code on any newly registered user. What action hook and code can I use to get the user id’s of any newly registered users (purchaser or additional attendees)?

I found the action AHEE__EE_Registration_Processor__trigger_registration_update_notifications but I’m not sure how to get the related users, or test if they’re newly created.

Thanks!


Tony

  • Support Staff

April 4, 2017 at 5:26 am

Hi SMills,

New created users, as in newly create WP Users created by the WP User Integration add-on or something else?

(May seems like an odd question but just want to be sure)


SMills

April 4, 2017 at 6:13 am

Good question. Yes, we’re using the WP User Integration add-on. That add-on also creates a WP user for additional attendees, right?

Thanks!


Tony

  • Support Staff

April 4, 2017 at 6:31 am

That add-on also creates a WP user for additional attendees, right?

No it does not, not by default.

It only creates a user account for the primary registrant.

We do have a snippet that creates user accounts for each attendee, however note that its not the default behavior so may have unexpected results (although none that we know of):

https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_ee_process_multi_wpuser_for_attendees.php

Also, note within that function there is this hook:

do_action( 'AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_created', $user, $attendee, $registration, $password );

Which is fired for each user created from a registration, and also this hook:

do_action( 'AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_updated', $user, $attendee, $registration );

Which is fired each time a WP user is updated (not created)

Which should help with your initial question.


SMills

April 4, 2017 at 10:40 am

Thank you! Looks like that did the trick.


Tony

  • Support Staff

April 5, 2017 at 3:36 am

You’re most welcome, I’m glad that worked for you.


SMills

April 17, 2017 at 1:27 pm

Hey, Tony.

After upgrading EE core, the additional attendees are no longer registered as WordPress users. I’m still using the code here:
https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_ee_process_multi_wpuser_for_attendees.php#L5

thanks!


Josh

  • Support Staff

April 17, 2017 at 6:17 pm

Hi there,

May I ask are you logged in to the site when you register for the multiple attendees?


SMills

April 18, 2017 at 4:39 am

No, I’m not logged in. What we want is for all attendees to end up with WordPress user accounts, so I’m testing not logged in every time.

This is the code that never seems to fire, so the actual registration code never gets called:

`
function jf_ee_wpuser_for_attendee_set_hooks() {
if ( ! is_admin() ) {
remove_action( ‘AHEE__EE_Single_Page_Checkout__process_attendee_information__end’, array( ‘EED_WP_Users_SPCO’, ‘process_wpuser_for_attendee’ ), 11 );
add_action( ‘AHEE__EE_Single_Page_Checkout__process_attendee_information__end’, ‘jf_ee_process_wpuser_for_attendee’, 10, 2 );
}
if ( EE_FRONT_AJAX ) {
remove_action( ‘AHEE__EE_Single_Page_Checkout__process_attendee_information__end’, array( ‘EED_WP_Users_SPCO’, ‘process_wpuser_for_attendee’ ), 11 );
add_action( ‘AHEE__EE_Single_Page_Checkout__process_attendee_information__end’, ‘jf_ee_process_wpuser_for_attendee’, 10, 2 );
}
}
`


Josh

  • Support Staff

April 18, 2017 at 9:25 am

May I ask where do you have the code loading from? Is it from within an activated WordPress plugin?


SMills

April 18, 2017 at 9:32 am

It’s in the functions.php.


Josh

  • Support Staff

April 18, 2017 at 9:48 am

OK that’s why the code isn’t firing then. A theme’s functions.php file loads after the AHEE__EE_System__load_espresso_addons action hook. Which is too late.

There’s a nice explanation here:
https://knowthecode.io/timing-mistakes-removing-wordpress-callback-hook

You can load the code from
https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_ee_process_multi_wpuser_for_attendees.php#L5
into a site specific WordPress plugin and that will ensure the code executes early enough.

https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/


SMills

April 18, 2017 at 1:11 pm

Thanks! Looks like that did the trick.

The support post ‘Get all related user id's when tickets are purchased.’ 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