For some membership site setups, it makes sense to use a different user registration process than the built-in PMPro Membership Checkout process.

But how do you give these users a membership level when they aren’t using our plugin’s checkout page?

In this recipe, we show you how to assign a free default membership level when users register through another method on your site. This code recipe works for sites that register users through the default WordPress user register screen, BuddyPress, BuddyBoss, WooCommerce and more.

Banner for Advanced Code Recipe Tutorial for Paid Memberships Pro

About the Hooks and Functions in this Code Recipe

user_register Hook

The user_register hook in WordPress triggers immediately after a new user is registered. By attaching custom functions to this hook, developers can run additional actions. The code recipe in this post hooks into the user_register action to make changes to the new user that is created. You can also use this hook to send custom welcome emails or log registration details to another table.

pmpro_changeMembershipLevel Function

The pmpro_changeMembershipLevel function is a key function used throughout Paid Memberships Pro. The function allows developers to programmatically change a user’s membership level. The code recipe in this post uses this function to assign the user a default membership level. You can also use this function to upgrade or downgrade memberships, add additional membership levels, or in any other custom workflow you need.

The Code Recipe

The code recipe below assigns a default membership level to the new user right after the user registration.

You must change the default membership level ID by editing line 27.

Not sure where to find your level IDs? Navigate to Memberships > Settings > Levels. Each level’s ID is in this list of levels.

Screenshot of navigation to locate membership level IDs

Caveats and Limitations of The Code Recipe

It’s important to note that this code recipe does not accept any payments or process any membership subscription payments, so it’s best for 100% free membership levels.

The recipe also does not set an expiration date on the membership, although this is possible by modifying the example code.

Finally, this code recipe only applies the default level for the initial user registration. If a user upgrades their membership after registration using the Paid Memberships Pro checkout and then cancels their higher-tier level (or it expires), the default level will not be reassigned.

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.

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics
Was this article helpful?
YesNo