Advanced Dynamic Pricing For WooCommerce

Paid Memberships Pro, by Stranger Studios

Paid Memberships Pro by Stranger Studios is one of the most widely used membership plugins for WordPress. It manages its own membership levels independently of WordPress’s native role system, storing them in custom database tables. Because of this, Advanced Dynamic Pricing for WooCommerce cannot detect a customer’s membership level out of the box — its rule engine only reads standard WordPress roles by default.

This article explains how to expose Paid Memberships Pro membership levels to Advanced Dynamic Pricing using two short filter hooks, enabling you to create membership-based pricing rules that apply automatically to members at checkout.


Required Settings Before Adding the Code

Before applying the compatibility snippet, you need to change two settings inside Advanced Dynamic Pricing. Both must be saved or the code will not work as expected.

Go to Advanced Dynamic Pricing → Settings → Calculation and make sure “Use prices modified by other plugins” is turned ON. Then go to Advanced Dynamic Pricing → Settings → System and make sure “Suppress other pricing plugins in frontend” is turned OFF. Save both settings pages before continuing.


Code Sample

Add the following snippet to your child theme’s functions.php or the Code Snippets plugin:

 

Code Explained (for Developers)

The snippet is structured as a helper function and two filter hooks that work as a matched pair — one for the admin rule builder, and one for the runtime rule engine.

Helper function — wdp_get_all_memberships_levels()

ElementDescription
$wpdb->pmpro_membership_levelsThe Paid Memberships Pro custom database table containing all configured membership levels. The isset() check confirms the table exists before querying — preventing errors if the plugin is deactivated.
$wpdb->get_results(...)Fetches all membership levels ordered alphabetically by name. Both filters below call this helper, avoiding duplicated query logic.

Filter 1 — wdp_preloaded_list_user_roles

ElementDescription
wdp_preloaded_list_user_rolesAn Advanced Dynamic Pricing filter that populates the role/group selector in the rule builder admin. Membership levels are appended here alongside standard WordPress roles.
'id' => 'membership_' . $level->idA unique identifier for each membership level using the membership_ prefix. This prefix distinguishes PMP levels from standard WordPress role IDs in the rule engine.
'text' => '(membership) ' . $level->nameThe human-readable label shown in the rule builder dropdown, e.g. (membership) Gold or (membership) VIP.
function_exists() guardSilently skips populating the list if the helper function is unavailable for any reason, preventing fatal errors.

Filter 2 — wdp_current_user_roles

ElementDescription
wdp_current_user_rolesAn Advanced Dynamic Pricing filter that provides the list of role/group identifiers for the currently logged-in user. The rule engine evaluates this list against active rule conditions at runtime.
pmpro_getMembershipLevelsForUser()Paid Memberships Pro’s own function that returns all active membership levels for a given user ID. Called here with get_current_user_id() so guest users (ID = 0) are handled safely.
array_column( $user_memberships, 'id' )Extracts just the level IDs from the returned membership objects, keeping the data transformation clean and minimal.
array_map( function( $id ) { return 'membership_' . $id; }, ... )Maps each level ID to the same membership_{id} format used in Filter 1, ensuring the rule condition matching works correctly.
array_merge( $roles, $user_memberships )Appends the membership identifiers to the existing roles array rather than replacing it, so standard WordPress role conditions continue to work alongside membership conditions.

Key concept: Filter 1 ensures membership levels can be selected when building a rule in the admin. Filter 2 ensures the rule applies correctly to eligible members on the front end. Both must be present for the integration to work.


Creating a Membership-Based Pricing Rule

Once the snippet is in place and settings saved, creating a membership-specific rule is straightforward. Go to Advanced Dynamic Pricing → Rules → Add New Rule, add a User Role condition, and open the role selector dropdown. You will see your Paid Memberships Pro levels listed with the (membership) prefix alongside standard WordPress roles. Select the target level, configure your discount, and save. Members at that level will automatically receive the discount the next time they browse your store or add a product to their cart.


How to Apply This Code

  1. Go to Advanced Dynamic Pricing → Settings → Calculation and enable “Use prices modified by other plugins”. Save the page.
  2. Go to Advanced Dynamic Pricing → Settings → System and disable “Suppress other pricing plugins in frontend”. Save the page.
  3. Open Appearance → Theme File Editor in your WordPress admin, or open the Code Snippets plugin.
  4. Paste the full snippet into your active child theme’s functions.php or create a new dedicated snippet.
  5. Save the file or snippet.
  6. Go to Advanced Dynamic Pricing → Rules and create or edit a rule.
  7. Add a User Role condition and open the selector dropdown — confirm that your Paid Memberships Pro membership levels appear prefixed with (membership).
  8. Log in as a user with an active membership and verify the discount is applied correctly on a product page, cart, and checkout.

⚠️ Always use a child theme or Code Snippets rather than editing the parent theme’s functions.php directly — parent theme files are overwritten on theme updates.


When Should You Use This?

This setup is the right approach when you use Paid Memberships Pro to segment customers into tiers — for example Silver, Gold, and VIP members — and want each tier to receive a different price, discount, or set of pricing rules managed entirely within Advanced Dynamic Pricing. It is also useful when you want to combine membership conditions with other Advanced Dynamic Pricing conditions such as minimum cart amount, specific product categories, or purchase history, giving you fine-grained control over which members receive which promotions.

Have questions? Please submit a support request. We're always happy to help!

Advanced Dynamic Pricing
for WooCommerce
PRO

From $60
Buy
✓ 30-day money-back guarantee