Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save digisavvy/1dbc2842857650fcbfbf17cdccec8361 to your computer and use it in GitHub Desktop.
Save digisavvy/1dbc2842857650fcbfbf17cdccec8361 to your computer and use it in GitHub Desktop.

Overview

The [mepr-membership-price] shortcode displays the price of a MemberPress membership and supports automatic coupon application, making it perfect for creating custom pricing displays that dynamically update when coupons are applied. Basic Usage [mepr-membership-price id="123"] This displays the regular price of the membership with ID 123. Parameters Required Parameters

id - The ID of the membership to display the price for

Optional Parameters

coupon - Accepts either:

A specific coupon code: coupon="DISCOUNT20" The value "param": coupon="param" (uses coupon from URL parameter)

diff - When set to "true" with a coupon, shows the discount amount instead of the final price

Example: diff="true"

format - Controls the format of the displayed price

format="dollars" - Shows only the whole dollar amount format="cents" - Shows only the decimal portion

Examples Basic Price Display [mepr-membership-price id="123"] Price with Specific Coupon [mepr-membership-price id="123" coupon="SAVE20"] Price with URL Parameter Coupon [mepr-membership-price id="123" coupon="param"] When a user visits with ?coupon=SAVE20 in the URL, the discounted price will be shown. Show Discount Amount [mepr-membership-price id="123" coupon="param" diff="true"] This shows how much the customer saves instead of the final price. Complete Pricing Display Original price: $[mepr-membership-price id="123"] Your price: $[mepr-membership-price id="123" coupon="param"] You save: $[mepr-membership-price id="123" coupon="param" diff="true"] How It Works The shortcode uses the following logic to determine the displayed price:

It retrieves the membership object using the provided ID If a coupon parameter is present:

If coupon="param", it checks for a coupon code in the URL parameter ?coupon=CODE If a specific coupon code is provided, it uses that code

It calculates the adjusted price using the membership's adjusted_price() method with the coupon code If diff="true" is set, it calculates and displays the discount amount instead of the final price The price is formatted using WordPress's currency formatting functions

Use Cases

Custom Pricing Tables: Create custom pricing tables in page builders like Bricks Special Pricing Pages: Build landing pages with coupon-specific pricing Showing Savings: Highlight the discount amount to encourage conversions Auto-applying Coupons: Use with URL parameters for marketing campaigns

Code Location The shortcode is defined in the MemberPress core files:

Registration: MeprProductsCtrl.php (~line 39) Implementation: MeprProductsCtrl::shortcode_price() method (~line 772)

Notes

This shortcode works seamlessly with the MemberPress registration forms When a coupon is applied in the registration form, any instances of this shortcode on the page will update automatically URL parameter coupons (using coupon="param") are automatically applied when the page loads The shortcode can be placed anywhere on the page, not just within MemberPress elements

I hope this documentation helps you and the MemberPress support team! This is definitely a useful feature that deserves proper documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment