Support

Home Forums WP User Integration Map and sync EE4 answers with custom user fields

Map and sync EE4 answers with custom user fields

Posted: October 1, 2021 at 3:17 pm


PTOee4

October 1, 2021 at 3:17 pm

Hello.
I am using EE4 + WP User Integration add-on. I am also using ACF Advanced Custom Fields where I have a few custom user fields (e.g. country, address, city, state, zip, company).

What I would like to do:
1) When an attendee registers for an event, it saves answers from the registration form to the custom user fields.
2) Optionally, it auto-populates these fields in the EE registration form if they’re logged in (syncing).

I do not think these snippets quite suffice: https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/mn_wp_user_addon_save_custom_answers_too.php or https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_filter_address_answer_for_wpuser.php or https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_ee_process_multi_wpuser_for_attendees.php

I’ve looked thru: https://eventespresso.com/topic/wp-user-integration-to-auto-fill-custom-fields-only-on-a-new-registration/ and https://eventespresso.com/topic/sync-event-registration-form-with-custom-user-fields/ and https://eventespresso.com/topic/linking-exiting-user-fields-with-the-user-integration-plugin/ and https://eventespresso.com/topic/auto-fill-in-form-all-fields-with-user-integration/ and https://eventespresso.com/topic/upon-registration-create-user-and-store-all-registration-fields-in-user-meta/ -this last one seemingly the closest to my goals.

But I’m not sure I’ve found what I’m looking for. Also thinking, as ACF and EE4 are both widely used plugins, ‘I can’t be the first person to try this’ :). Any guidance or suggestions would be deeply appreciated. Or if I’m missing something. Thank you.


Tony

  • Support Staff

October 4, 2021 at 7:55 am

Hi there,

The bigger picture for this is you’ll now have multiple places where those details are stored which needs to be managed.

Event Espresso stores the address info with the EE_Contact, aka the Attendee. You can see that in Event Espresso -> Registrations -> Click on the icon for a registration.

Now you are editing the EE_Contact for that registration and you can see it stores the address info there. You’ll need to keep that in sync with your custom values and it adds an extra layer that we (Event Espresso) don’t need to include in the mix so don’t support currently, although anyone who wants to do so is more than welcome to 🙂

For example, if you are allowing users to edit those values outside of just the EE registration form there will be times when the WP User ACF values won’t match up to the EE_Contact address values (unless you write a custom function to sync them on update from wherever they are being updated). The method I’m referring to below works around that a little, but it’s still very easy for those values to be out of sync for some time.

1) When an attendee registers for an event, it saves answers from the registration form to the custom user fields.

This can be done with the AHEE__EE_Single_Page_Checkout__process_attendee_information__end action so you can hook in, pull the primary registration from the checkout and update ACF values from the attendee object value (they’ve already been set and saved within EE at this point).

The model system makes getting the data you need fairly straight forward and if you are not familiar with using it I recommend reading these:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

A lot of what you need to do in this step is completely outside of Event Espresso.

2) Optionally, it auto-populates these fields in the EE registration form if they’re logged in (syncing).

So you’re making the ACF files the ‘primary values’ for those fields?

You already have most of what you need for this with this snippet:

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

That snippet is checking the registration form files as they are generated and for the address fields, it populates a value using the $attendee object. You just need to swap out the value for whatever is currently used by the ACF values on the user.

For example on this line:

Rather than using $value = $attendee->get( 'ATT_address' );

Set $value to whatever your custom ACF field value is for address, you have the global current user in that function to pull whatever you need from there.

Now the fact that the above values are pulled from the ACF values means that the attendee will be updated with those values when the user registers onto the event, so if the ACF values were updated outside of an EE registration, they should now sync up with the EE_Attendee.

You must be logged in to reply to this support post. Sign In or Register for an Account

Event Espresso