Support

Home Forums WP User Integration Update Buddypress custom xprofile field from EE event registration form

Update Buddypress custom xprofile field from EE event registration form

Posted: July 15, 2019 at 12:08 pm


a608237

July 15, 2019 at 12:08 pm

I purchased WP User Integration with Event Espresso. When registering for events, guests now have to log in (which is desired).

But, I also have custom profile fields in buddypress (i.e. Gender, age, education), for which I’ve also included as custom fields in the event registration form (EE). How can I easily take what a User submits in the EE custom fields and update the matching Buddypress custom profile fields with it? This feature seems to be available for First Name, Last Name, and email only. Thanks in advance.


a608237

July 15, 2019 at 12:10 pm

i see that the values are stored in esp_answer.ANS_value. Is there a way to update buddypress profiles with the data without manually creating some kind of SQL trigger?


Tony

  • Support Staff

July 15, 2019 at 12:40 pm

Hi there,

First Name, Last Name and Email are the only values synced from EE to the WP user profile currently, so to update other meta fields you’ll need custom code either way.

I’m guessing payment/registration status doesn’t matter here? Meaning you just want the values updated as soon as you have them available to you?


a608237

July 15, 2019 at 12:45 pm

The user is already able to update the meta fields from their bp profile page, but the EE event registration should allow them the opportunity to enter new values, and if they do, should update the corresponding bp meta fields.

It’s meant to be an alternate means to update bp meta fields if necessary.

i.e. If the user’s buddypress Education field is ‘High School’, and later on, he registers for an event as a ‘Bachelor of Science’, the buddypress profile field Education ought to catch it from the EE form. Hopefully that makes sense.


Tony

  • Support Staff

July 15, 2019 at 12:59 pm

Yeah, I understand what you are trying to do, but what should happen if the user registers onto a ticket, enters their details (including the Education field) as above and then does not continue payment… should the value still be updated?

I’m assuming it should be but people want this to work in different ways and it’s the differences which determine the hook you need to use.

So far it sounds like you could use the AHEE__EE_Single_Page_Checkout__process_attendee_information__end hooks (which is the same hook used by the WP User Integration add-on to pull the registration(s) and update the meta fields.

Meaning you’d hook in and pull the answers for the custom questions on your registration form, then use the values to update the user meta/bp fields.


a608237

July 15, 2019 at 3:13 pm

Hi Tony,

THanks for that hook you provided. I tried to google/search this forum for examples on how that hook works and it’s not yet very clear to me. I’ve seen different argument types passed to it ($this, $valid_data, 10, 2, integers). Can you provide a brief example of how it works? Suppose my custom registration field is Education, how might AHEE__EE_Single_Page_Checkout__process_attendee_information__end capture it? I will try to feed it into corresponding buddypress profile fields.

I’d really like to dodge hiring a developer to write code where possible.

Thanks!


Tony

  • Support Staff

July 16, 2019 at 4:17 pm

The best example I can give you is the method from the User integration add-on

\eea-user-intergration\EED_WP_Users_SPCO.module.php::process_wpuser_for_attendee()

The filter is passed an EE_SPCO_Reg_Step_Attendee_Information object and the $valid_data variable containing all of the data validated by SPCO…. however, for your use case you should probably ignore it and use the models to pull all of the details you need, just like the above method does.

If you don’t want to hire a developer to code this for you, you’ll need to learn how to use our models to pull the details you need, you’ll find the docs here:

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

Here is an example that uses our models system to pull the value of a question liked to a registration object ($item) using the question ID.

That should get you most of what you need.


a608237

July 16, 2019 at 4:34 pm

Sir,

by some horrible, utterly horrible experimentation, I have figured it out. Using the sample code here: https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/mn_wp_user_addon_save_custom_answers_too.php
I substituted line 23 with my own question ID(s) in question and created a variable for each answer I wanted to store.

BUT for the longest time, the $prev_answer_value constantly returned the custom answer equal to the number of different questions I had. For example, if I had 5 questions, and the answer to my variable $education_level was ‘Elementary’, $prev_answer_value would yield ‘Elementary Elementary Elementary Elementary Elementary’.

It was not until I insert the variables for my $prev_answer_values on line 37 (before return $input_args) did it return the string answer once, rather than multiple times. Can you elaborate on how the code pulls the answers, and why it was happening repeatedly? How might one tell it to pull 1 instance of the answer earlier?

Thank you!


Tony

  • Support Staff

July 17, 2019 at 2:34 am

Without knowing the exact changes you made I can’t say.

The query for the answer has a limit of 1, meaning 1 value should (and when using that example, is) be returned.

Are you also using the FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args hook to save the values? That filter is ‘fired’ when the inputs are constructed, meaning at the beginning of the Attendee info step before they have entered values.


a608237

July 17, 2019 at 8:04 am

If I had to guess, the code supplied performs the operation equal to the number of questions that there are, hence the multiplication of answers, but there does not seem to be a loop anywhere. It will forever be a mystery

I am using the hook FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args. It seems to be working as:
previous custom question answers are prepopulated on new registrations and custom answers are being synced to matching buddypress custom fields. What undesired behavior would you expect from the hook?


a608237

July 17, 2019 at 8:07 am

buddypress fields are being updated with something like xprofile_set_field_as('Education',$current_user_id, $prev_answer_value_education)

The support post ‘Update Buddypress custom xprofile field from EE event registration form’ 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.

Status: closed

Updated by  a608237 5 months ago ago

Topic Tags

Notifications

This topic is: resolved
Do NOT follow this link or you will be banned from the site!