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
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.
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
}
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
Hi there,
Thank you for purchasing our plugin,
You can find a partial list of meta keys used for dynamic rules here https://woocommerce-b2b-plugin.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
Thanks that's exactly what I needed.
Is there a way to get the name of Customer Group that a user is part of?
Yes, for the current user you can use the following code:
To check if that user is a B2B user:
To get a user's group and name of group:
That's great, last question, how do I get the credit limit and remaining credit for a group?