While MemberPress allows you to set standard pricing and basic coupon codes, advanced membership sites often require dynamic pricing logic. Whether you want to offer automated loyalty discounts based on user meta, adjust pricing dynamically for specific user roles, or implement custom volume-based pricing, hardcoded product prices in the dashboard won’t always cut it.
Fortunately, MemberPress provides powerful filters that allow you to intercept and modify product prices programmatically before the checkout form renders.
In this tutorial, we will explore how to change MemberPress product prices dynamically using PHP.
1. Understanding the Product Price Filter
When MemberPress renders a product price on checkout or pricing tables, it runs through the mepr-product-price filter. By intercepting this filter, you can evaluate the current user, product ID, and original price, then return a modified numerical value.
Add the following code to your custom plugin or theme’s functions.php:
if (!defined('ABSPATH')) {
exit;
}
add_filter('mepr-product-price', 'wg_custom_dynamic_membership_price', 10, 2);
function wg_custom_dynamic_membership_price($price, $product) {
// $price is the float value of the product price
// $product is an instance of MeprProduct
// Example: Target a specific product ID (e.g., ID 100)
if ($product->ID !== 100) {
return $price;
}
// Check if user is logged in
if (is_user_logged_in()) {
$user_id = get_current_user_id();
// Check if user has a specific custom meta tag (e.g., VIP client status)
$is_vip = get_user_meta($user_id, 'wg_is_vip_client', true);
if ($is_vip) {
// Apply a 20% discount dynamically
$price = $price * 0.80;
}
}
return round($price, 2);
}
2. Applying Dynamic Pricing Based on Existing Memberships
Another common requirement is offering a discounted upgrade price if the user is already subscribed to a lower-tier plan. You can combine the MemberPress user class with our pricing filter:
add_filter('mepr-product-price', 'wg_upgrade_discount_pricing', 10, 2);
function wg_upgrade_discount_pricing($price, $product) {
// Only apply for our Pro Membership (Product ID 200)
if ($product->ID !== 200) {
return $price;
}
if (is_user_logged_in()) {
$mepr_user = MeprUtils::get_current_mepr_user();
// Check if user holds an active subscription to the Basic Plan (Product ID 150)
if ($mepr_user && $mepr_user->is_active_member_in_product(150)) {
// Give a flat $50 discount for upgrading
$price = max(0, $price - 50.00);
}
}
return $price;
}
3. Important Considerations for Dynamic Pricing
Recurring Subscriptions: If you modify the price of a recurring subscription product, note that gateway APIs (like Stripe or PayPal) will bill the modified price for all subsequent renewal cycles unless handled via custom gateways.
- Caching: If your site uses aggressive object caching or full-page caching (like Redis or Varnish), ensure that dynamic pricing pages bypass cache for logged-in users so prices render correctly per user session.
Using the mepr-product-price filter lets you build complex, personalized pricing models, automated loyalty tiers, and intelligent upgrade paths directly into your MemberPress architecture.
Be sure to check out our previous tutorials on WordPress development:
How to Handle MemberPress Events & Webhooks in PHP
How to Check MemberPress Subscriptions & Redirect Users
How to Add & Process Custom Fields in MemberPress
Need help with your project? We will be happy to help with your project. Feel free to contact us. Just reach out and we will reply soon.