Support

Home Forums WP User Integration EE4 – Assign a default membership level to new users upon registration

EE4 – Assign a default membership level to new users upon registration

Posted: June 7, 2017 at 8:40 am


ispcan

June 7, 2017 at 8:40 am

Hi,

Background:
-EE4
-WP User Integration
-PaidMembershipsPro

It is our hope to perform the following scenario:

1) When a non-member of our site registers for an event, EE4/WP-User will create a WordPress account for this user.
2) Upon creating the new WP user, we would like to set a default membership level to this new user (PaidMembershipPro).

Note: I was reviewing https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_ee_set_capability_default_user_create_role_event_editor.php – I see this is referring to s2 roles, however I’m not sure if this is even the correct hook to use.

Any advice is much appreciated – thanks.

– Christian


Josh

  • Support Staff

June 7, 2017 at 10:14 am

Hi Christian,

You can assign a default membership level to new users upon registration in Event Espresso > Registration Form > WP User Integration settings > Default role for User Creation on Registration.

The code snippet you reviewed is useful for removing choices from that selector. The selector grabs all user roles, but you may wish to remove some of those choices by applying that code.


Tony

  • Support Staff

June 7, 2017 at 10:23 am

Hi Christian,

If I recall correctly, PMP does not use ‘roles’ in the same way S2 or similar does, I think the membership level is completely separate from the WP User role.

If that’s the case the hook you’ll likely want to look into is:

AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_created

That would be fired specifically for users created by EE so you can then run pmpro_changeMembershipLevel() within that hook to set the membership level.

You could also use the wp hook set_user_role but the above gives you more granular control over Users created by EE.


ispcan

June 7, 2017 at 10:34 am

Thank you both.

@Tony – We are using an addon that allows us to define custom roles for PMP, but in reality AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_created
with
pmpro_changeMembershipLevel()
Seems like it would be a much cleaner approach.

Thank you again for the tips – I will report back if I encounter any other obstacles.


Tony

  • Support Staff

June 7, 2017 at 10:49 am

We are using an addon that allows us to define custom roles for PMP

If that add-on hooks into set_user_role or similar and checks if a PMP has been used, then calls pmpro_changeMembershipLevel() itself you may find that it just works with the role selected in the event, but again, I’m not 100% sure.


ispcan

June 13, 2017 at 8:27 am

Thanks. I’ve been able to successfully create and assign membership levels using the above info.

I have a follow-up question:

Is it possible to identify the ticket selected for an event registration?

My hope is to be able to be able to auto create membership, using the above, based on the type ticket selected.

In other words, if user selects a ticket that includes membership, invoke
pmpro_changeMembershipLevel()
Else if they select another ticket, WP User Integration creates a WordPress user, without any membership level tied to it.

Hope this makes sense – let me know if this makes sense or if you need me to clarify anything.

Thanks,
Christian


Tony

  • Support Staff

June 13, 2017 at 9:14 am

Using the hook I mentioned above?

Registrations have a one-to-one relationship with tickets so if you have a registration, you have the ticket fo that registration. You need to have an instance of EE_Registration then you can pull the ticket for that registration using something like:

$ticket = $registration->ticket();

Then $ticket will be an instance of EE_Ticket which you can pull various details from.

I’d recommend installing Kint and then wrapping the objects in d(); to view all of the available methods available for each object, or you can view the code and work through it that way if preferred.

The support post ‘EE4 – Assign a default membership level to new users upon 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.

Event Espresso