This recipe changes a user’s membership level when they cancel or their subscription expires. After the expiration or cancellation, that user will have no membership level. This code triggers to assign a free default level.

Sites that offer a “free” membership level can use this code to place premium members into the free level after cancellation. Or, you can use this code to assign a hidden membership level so that you can later target these users through winback campaigns and email sequences.

Banner for Advanced Code Recipe Tutorial for Paid Memberships Pro

How it Works

In this example we are checking for $level_id == 0 which indicates an account that has been cancelled or has expired.

Once we know the account has $level_id == 0 (no level), we use the pmpro_changeMembershipLevel() function to change that user’s membership to $level_id == 1. Level 1 in this case might be a “free” subscription account, but you’ll want to make sure you choose the right level when using this function. Another thing to keep in mind is that this particular function will work across all user accounts on a site.

Code Recipe #1: Change Membership Level on Cancellation or Expiration

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.

Customize this code with your appropriate level ID for the cancellation downgrade.

Code Recipe #2: Change Membership Level on Expiration Only

Code Recipe #3: Allow Users to Cancel Their “Default” Level

As an alternative to the recipe above, this code allows users to cancel from the default level. With this recipe, the same logic to give users the default level on cancellation only applies if they are cancelling from “higher” level.

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