Give your customers the option to select a membership duration and offer them a discount for a longer term when selling non-recurring memberships. This is a great way to collect a larger up-front payment from members and offer an incentive to pay for membership in advance.
In this code recipe, we demonstrate how to offer a 20% discount when members prepay for 2 years of membership and a 25% discount for members that purchase a 3 year membership in advance. If you have a membership level with a recurring subscription and would like to configure something similar we recommend using the Payment Plans Add On.
About the Recipe
This code will add a “Membership Duration” dropdown field to your checkout page. Once selected, the membership checkout information will be updated to the appropriate expiration date and the initial payment amount will be charged immediately at checkout. This code is best used for a base level that has a fixed one-year membership term (Do not set up the level to have a recurring payment. Instead, only set an initial payment amount and expiration date of 1 Year).
This code recipe serves as an example for what is possible—you should alter the recipe to fit your needs, such as removing or adjusting the discount to suit your business.
The Code Recipe
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.
Update lines 35-39 to adjust the membership duration terms you want to offer for your members. In this recipe, we offer a 1, 2, and 3 year option. You could optionally show the adjusted checkout total price once the discount is applied in the field label (as shown in the screenshot above).
On line 40, you can adjust the level ID that should show the membership duration dropdown field. If you want to show this for more than one level ID, it would be best to duplicate the field and rename it for each unique level ID > duration discount you offer.
Finally, edit or duplicate lines 79-89 for each duration option in your select field. You should adjust the duration value (number of cycles/periods) and the discount percentage for each choice. If you prefer to adjust this for a monthly membership, you will also need to adjust line 98 and change it to the string ‘Month’.
If you need help altering this code to suit your needs, feel free to get in touch with one of our support team.
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.