Posted: March 9, 2022 at 3:25 pm
I am trying to add a user to a Buddyboss group when they successfully register for an event. I have used ACF to create a field for the event – called ‘event_sub_group’. This allows the admin to choose a BuddyBoss group on the event page. This is set to return the post id of the selected group. I then have the following in my site plugin:
if ( $registration instanceof EE_Registration ) { $subgroup = get_field('event_sub_group', $event_id); if (!empty($subgroup)) { I have also tried using the hook ‘AHEE__EE_Registration__set_status__after_update’ with no success. I know the code to add a user to a group works as I use it elsewhere Am I getting something totally wrong? (I’m not overly experienced!) Thanks in advance! |
|
Hi there, Before going into details for this a little further, I need to ask:
Can you define what you mean by ‘successfully register for an event’, please? It means different things to different people and the hook you use will depend on your definition. For example are the tickets paid or free? If paid, is a successful registration only after the registration has been paid for and the registration status set to Approved or should the above group be set as soon as they start a registration? Just some notes to help with your code when using the models: —–
First, The EE_Registration class has a method for grabbing the event id:
Why is that different? Because
—
Either declare it somewhere or, what I would do is something like:
Small change but exists out of your code if it doesn’t have the data it needs (no point running any of the above group code if you don’t have an event_id). The rest looks fine assuming you need to set the global current group, but I don’t use BuddyBoss so won’t comment further on that code, if its working elsewhere, great. Have you checked that code is actually running when you expect it to? You mentioned your code works elsewhere, have you confirmed to see if any of the above is actually running? |
|
Thanks for the detailed reply Tony. These particular tickets are free, but I can see a use case in the future for paid tickets – so probably a hook that comes after ‘payment’? Is there one that fires for either a free or paid ticket only after the registration has been paid for and the registration status set to Approved? I’ll fix up the other areas you pointed out – thanks! |
|
There is a hook which fires when the registration status is set to Approved:
Which is an action:
From there you function would be:
You compare the old and new status values if needed to then only do something when for specific status changes, but the above should be enough for most registration types to work. Try using that hook and output something to a log file to confirm your code is actually running when expected, then move onto trying to set the BuddyBoss groups. |
|
Thankyou. It’s working, but the issue was actually with the Buddyboss part of the code. I can get the Post ID for the group, but this is not the Group ID, so I need to figure out a way to get the Group ID from the Post ID. Thanks for your help – on to the next problem through the Buddypress forums π |
|
Ah, great π I’m glad you found the problem, if I can help with anything else just let me know. |
|
The support post ‘Hook / Code to add user to Buddyboss group on event registration’ 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.