Advanced Dynamic Pricing For WooCommerce

Groups (use group/role discounts), by itthinx

Groups by itthinx is a popular WordPress plugin for managing user groups and access control. Unlike WordPress’s native role system, Groups creates and manages its own group memberships stored in custom database tables — meaning standard WordPress role-based conditions in Advanced Dynamic Pricing for WooCommerce cannot detect them out of the box.

This article explains how to bridge the two plugins using two filter hooks that expose Groups memberships to Advanced Dynamic Pricing’s rule engine — enabling you to create group-based discount rules just like role-based ones, targeting specific customer groups with tailored pricing.


Required Settings Before Adding the Code

Two plugin settings must be configured correctly before applying the compatibility code. Without these, group-based pricing rules will not fire correctly.

In Advanced Dynamic Pricing → Settings → Calculation:

SettingRequired value
Use prices modified by other plugins✅ Must be ON

In Advanced Dynamic Pricing → Settings → System:

SettingRequired value
Suppress other pricing plugins in frontend❌ Must be OFF

⚠️ Save both settings pages before applying the code snippet below.


Code Sample

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

 Code Explained (for Developers)

The snippet provides two complementary filters. The first populates the admin rule builder with your Groups groups. The second tells the pricing rule engine which groups the currently logged-in customer belongs to at runtime.


Filter 1 — wdp_preloaded_list_user_roles

This filter populates the role/group dropdown in the Advanced Dynamic Pricing rule editor so that your Groups groups appear alongside standard WordPress roles when creating conditions.

ElementDescription
wdp_preloaded_list_user_rolesAn Advanced Dynamic Pricing filter that provides the list of available roles and groups shown in the rule builder’s user role/group condition selector.
$listAn array of existing entries, each with an 'id' and 'text' key. WordPress roles are already present here; this filter appends Groups groups to the same array.
function_exists( '_groups_get_tablename' )Safety check — confirms the Groups plugin is active and its internal functions are available before attempting any database queries. Prevents PHP fatal errors if Groups is deactivated.
_groups_get_tablename( 'group' )Groups plugin internal function that returns the correct prefixed database table name for the groups table (e.g. wp_groups_group).
$wpdb->get_results(...)Fetches all groups from the Groups database table, ordered alphabetically by name.
'id' => '(group)' . strtolower( $group->name )Constructs a unique identifier for each group using the (group) prefix followed by the lowercase group name. This prefix distinguishes Groups entries from standard WordPress role IDs in the rule engine.
'text' => '(group) ' . $group->nameThe human-readable label displayed in the rule builder dropdown, showing the (group) prefix and the original group name with its original casing.

Result: After applying this filter, when you create or edit a pricing rule in Advanced Dynamic Pricing and add a User Role condition, your Groups groups will appear in the dropdown prefixed with (group) — for example: (group) wholesalers, (group) vip customers.


Filter 2 — wdp_current_user_roles

This filter injects the current user’s group memberships into the pricing rule engine at runtime, so rules that target specific groups are evaluated correctly for each customer.

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 compares this list against the conditions defined in each rule to determine which rules apply.
$rolesThe existing array of role identifiers for the current user — standard WordPress roles are already present. This filter appends the user’s Groups memberships.
get_current_user_id()Returns the WordPress user ID of the currently logged-in customer. Returns 0 for guests — the database query is skipped in that case since guests have no group memberships.
_groups_get_tablename( 'user_group' )Returns the correct prefixed name of the Groups user-group relationship table (e.g. wp_groups_user_group), which maps user IDs to group IDs.
SubquerySELECT group_id FROM {$user_group_table} WHERE user_id = {$current_user_id} retrieves all group IDs the current user belongs to. The outer query then fetches the full group records for those IDs.
$roles[] = '(group)' . strtolower( $group->name )Appends each group membership as a role identifier using the same (group) prefix pattern used in Filter 1. This ensures the IDs match correctly when the rule engine evaluates conditions.

Result: When a logged-in customer views a product or adds an item to the cart, Advanced Dynamic Pricing checks their group memberships via this filter and applies any rules that target their group(s) — exactly as it would for standard WordPress role-based rules.


How It Works Together

The two filters work as a matched pair:

FilterPurposeWhen it fires
wdp_preloaded_list_user_rolesPopulates the admin rule builder dropdown with Groups groupsWhen editing a pricing rule in the WordPress admin
wdp_current_user_rolesTells the rule engine which groups the current customer belongs toOn every product page, shop page, cart, and checkout load

Without Filter 1, you cannot select a group as a rule condition in the admin. Without Filter 2, the rule engine would not know the customer is in a group even if a rule exists for it. Both must be active.


Creating a Group-Based Pricing Rule

Once the snippet is in place:

  1. Go to Advanced Dynamic Pricing → Rules → Add New Rule.
  2. In the Cart Conditions or Product Filters section, add a User Role condition.
  3. In the role selector dropdown, look for entries prefixed with (group) — these are your Groups groups.
  4. Select the target group (e.g. (group) wholesalers).
  5. Configure your discount (percentage, fixed amount, bulk tiers, etc.).
  6. Save the rule.
  7. Log in as a user who is a member of that group and verify the discount is applied.

How to Apply This Code

  1. Open Advanced Dynamic Pricing → Settings → Calculation and enable “Use prices modified by other plugins”.
  2. Open Advanced Dynamic Pricing → Settings → System and disable “Suppress other pricing plugins in frontend”.
  3. Save both settings pages.
  4. Open Appearance → Theme File Editor or the Code Snippets plugin.
  5. Paste the full snippet into your child theme’s functions.php or create a dedicated snippet.
  6. Save and go to Advanced Dynamic Pricing → Rules to verify that your Groups groups now appear in the User Role condition selector.

⚠️ Always use a child theme or Code Snippets — editing the parent theme’s functions.php directly will be overwritten on theme updates.

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