All of the content protection checks in PMPro are based on the user’s active level: if they have the level, they can see the content.
Some sites, especially those that with trials, may also want to check that the user has actually paid for membership. For example, in the case of free trials, some members have the level but have not yet made a payment.
This code recipe adds a new [haspaid]
shortcode to your membership site. Content creators can use this shortcode to show unique content to users who are within the trial period or for members that are fully active and paying.
About the [haspaid]
Shortcode
The [haspaid]
shortcode looks up a member’s order history and checks whether their current level or any past levels have a positive order total value.
Then, using shortcode attributes, you can show or hide special content only to members that match the shortcode criteria.
Showing Content to Unpaid Members
The image below shows an upgrade message for members on a free trial of level ID 1. That message only shows for users that NEVER made a payment for the level. This is the shortcode and content used to create that callout.
If you’re using the Memberlite Theme, you can use the button shortcode like this:
[memberlite_btn style="action" href="/membership-checkout/?pmpro_
level=1" text="Upgrade to Gold Membership" icon="heart"]
Members of level ID 1 that are paying (full members) will not see this callout or any interruption in the standard content of your page/post.
Showing Content to Downgraded Members
Another example of using this shortcode relates to members who previously held a higher tier membership and are now on a lower tier level. You can use the haspaid
shortcode in combination with the require membership shortcode or block to show an upgrade notice for this category of users.
Here’s an example of how this shortcode combination works:
[haspaid]
Shortcode Attributes
- paid: Accepts ‘true’ (has paid) or ‘false’ (hasn’t paid); default: true
- level: The level ID to check against. Accepts any level ID; default: none.
[haspaid] This will show up if the user has NOT paid for any level. [/haspaid]
[haspaid paid='0'] This will show up if the user has NOT paid for any level. [/haspaid]
[haspaid paid='1' level='1'] This will show up if the user has paid for level 1 specifically. [/haspaid]
[haspaid paid='0' level='1'] This will show up if the user has not paid for level 1 specifically. [/haspaid]
Required: The Shortcode 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.
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.