Public Ticket #3037854

Get meta for dynamic rules and groups

Closed
Comments
2 Tickets
nlittlesf started the conversation 4 years ago on May 5, 2022 at 9:28am

Hi,

I would like to get the meta for dynamic rules so I can display them in a banner. For example, a discount percentage on all products for Group A is 10%. 

I have been using get_the_author_meta() to get information on user-specific information, such as credit limits, however, I can't seem to find documentation on getting meta for the dynamic rules or groups

2,762
KingsPlugins replied 4 years ago on May 6, 2022 at 10:04pm

Hi there,

Thank you for purchasing our plugin,

You can find a partial list of meta keys used for dynamic rules here https://b2bkingplugin.com/docs/import-or-setup-dynamic-rules-programatically/

Generally speaking, you can use get_post_meta. Let me give a few examples:

For a discount percentage rule, you can:

-> Get the discount value: $value = get_post_meta($rule_id, 'b2bking_rule_howmuch', true);

-> Get the group it applies to $group = get_post_meta($rule_id, 'b2bking_rule_who', true); - this returns 'group_123', where 123 is the group id.

If you want to get all dynamic rules that apply to a specific user, you can use the function:

$rules = b2bking()->get_all_rules(); - this gets all rules that apply for the current user, returning an Array of rule IDs.

You can also specify rule type, and the user ID, for example: $rules = b2bking()->get_all_rules('discount_percentage', 1234); - this gets all discount percentage rules that apply to the user with ID 1234.

Kind regards,

Stefan

1
2,762
KingsPlugins replied 4 years ago on May 9, 2022 at 10:00am

Yes, for the current user you can use the following code:


To check if that user is a B2B user:

$user_id = get_current_user_id();
$is_b2b = get_user_meta($user_id,'b2bking_b2buser', true);
if ($is_b2b === 'yes'){
    // user is B2B, therefore you could proceed to get the group here
}

To get a user's group and name of group:

$group_id = get_user_meta($user_id, 'b2bking_customergroup', true);
$group_name = get_the_title($group_id);
1

Sign In