This code recipe gives users a membership level during the frontend WordPress User Registration. You can use this approach if you want to offer the traditional WordPress Registration process or have users register through another plugin’s front end registration, such as BuddyPress or WooCommerce.
Note that this code only applies the level on the initial user registration.
Let’s say you have a default free level for all users. If a user upgrades their membership after registration using the Paid Memberships Pro checkout and then cancels their paid or higher-tier level (or it expires), this default level will not be returned to them.
To automatically assign this default membership level when a user cancels or their different level membership expires, check out this code recipe: Change Membership Level on Cancellation or Expiration.
The Code Recipe
This code hooks into
user_register and calls the
pmpro_changeMembershipLevel function for the new user. Be sure to change the level id in the code to match the level you want to give.
Note: This approach will not process any membership subscription payments. It will only work if your default membership level is free.
Adding the Recipe to Your Website
You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.
pmpro_changeMembershipLevel function in this code with the correct level ID for your default level.