Many site owners want to limit the number of members that can sign up for a membership level. This is useful if you are restricting membership for a unique course or training experience, or just want to create some scarcity as a marketing tactic.

The recipe adds a setting on the Edit Membership Level admin screen where you can set a value for the Maximum Number of Members. Once that limit is reached, the system blocks additional membership checkouts.

Encourage visitors to join now by displaying this limit in your site in the format “2/10 spots available”.

Banner image for Limit the Number of Members by Membership Level

Components in This Code Recipe

This is one of our bigger code recipes, which we generally try to stay away from. That said, it’s a great example of all the ways you or your developer can hook into Paid Memberships Pro to add custom level settings and registration checks, as well as display information for users and admins. Here’s a list of the different ways this recipe modifies the site and limits checkouts:

Level Setting for the “Limit”

The first piece is the setting, stored in level meta, that admins can use to easily set the maximum number of members in the level. Two hooks are used to add this setting: pmpro_membership_level_after_other_settings (to show the field) and pmpro_save_membership_level (to save the field’s value when the level is saved).

Block Registration When the Limit is Reached

The next piece of this code add a registration check using the pmpro_registration_checks hook. The system triggers this code when the membership checkout form is submitted. It looks up the level’s limit value, checks it against the total count of active members in the level, and either allows checkout to process or blocks checkout.

Display the Limit to Members at Checkout

So members can see the scarcity or popularity of the level, this code includes two options to display the limit on the membership checkout page. One option is to show the number of spots claimed (active members in the level) and another is to show the number of spots available. You can pick which you want to show by editing the code recipe to your liking. The code uses the pmpro_checkout_after_level_cost hook to show this extra text on the checkout page.

Redirect Away From Checkout if the Limit is Reached

Once the limit is reached, there is no reason anyone should be able to access the checkout page. This recipe has a function that uses core WordPress’ template_redirect hook to check if someone is on the checkout page for a level that has no available slots. If that level is not available, the system redirects the visitor to the levels page.

Hide the Level From the Membership Levels Page

For any level that has zero spots available, this code recipe will filter it out from displaying on the frontend Membership Levels page using the pmpro_levels_array filter.

Show Admins the Limit and Active Members on the Levels Admin

The final piece of this code recipe hooks into the list of levels on the Memberships > Settings > Levels screen. The code adds a new column to this table with the number of active members and the limit. The two hooks used to show this column are pmpro_membership_levels_table_extra_cols_header and pmpro_membership_levels_table_extra_cols_body.

Show Limited Number of Seats Available

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.

Set the Membership Limit maximum value on the Memberships > Settings > Membership Levels > Edit Membership Level admin page.

You can customize the text displayed in your level description by editing lines 110 to 129. The output of this limit can be styled using the CSS class selectors: .my-pmpro-spots-claimed or .my-pmpro-spots-available.

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