Since the success of a membership site depends largely on recurring payments over the long-term, member retention is crucial. Reducing churn and winning back lost customers are parts of that equation.
This code recipe generates a unique one-time discount code for a member’s current level when their user account expires—incentivizing potentially lost members to stick with your membership.

The Code Recipe (PHP)
Add the variable !!expired_code!!
to the Membership Expired email to show the code to users.
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.