Our customers fall into 3 groups depending on the discount they have. We want to create a group-level rule so that customers with a lower discount automatically enter the group with a higher discount if they place an order of a certain value.
Unfortunately, I noticed that we can only choose as a condition the value of the orders from a month, from a year or the total value of all orders.
To qualify for a higher discount level, our customers must make a single order of a certain value. Is it possible to set such a condition?
Just to make sure I understand this correctly: this cannot be achieved through the total order value setup?
In other words, let's say you want the group change to happen on single orders over $1000.
Does that mean the group should be changed if the customer orders $1000 one time, but should NOT be changed if the customer places 2 orders, of $500 each?
These are the qualification rules for a higher company discount, the customer must place a single order of a certain value and not several cumulative orders.
There is no default feature for that in B2BKing, but I tried writing a custom code snippet to help you achieve this.
This is the code:
add_action( 'woocommerce_checkout_order_processed', 'b2bking_group_rules_apply', 10, 3 );
add_action( 'woocommerce_blocks_checkout_order_processed', 'b2bking_group_rules_apply', 10, 3 );
function b2bking_group_rules_apply($order_id, $posted_data, $order){
// enter values
$oldgroup_id = 1234;
$newgroup_id = 4567;
$order_threshold = 1000;
// values
$update = false;
$order = wc_get_order($order_id);
$user_id = $order->get_customer_id();
$user_id = b2bking()->get_top_parent_account($user_id);
$order_total = $order->get->total();
$currentusergroupidnr = b2bking()->get_user_group($user_id);
$is_b2b_user = get_user_meta( $user_id, 'b2bking_b2buser', true );
if ($is_b2b_user === 'yes'){
// if $order is above threshold
if ($order_total > $order_threshold){
// if user has old group, update to new group
if ($currentusergroupidnr == $oldgroup_id){
b2bking()->update_user_group($user_id, $newgroup_id);
$update = true;
}
}
}
// delete all b2bking transients
// Must clear transients and rules cache when user group is changed because now new rules may apply.
if ($update){
b2bking()->clear_caches_transients();
b2bking()->b2bking_clear_rules_caches();
}
}
In the code you must set 3 values there at the beginning of the snippet, the order value threshold (e.g. $1000), the old group ID, and the new group ID.
To get a group's ID, you can edit that group in the backend (in b2bking->groups->business group, click on a group), and check the number in the URL. The number in the URL (e.g. ?post=1234) is the ID of the group.
We can help set it up directly on your site if you'd like. For that I'd need a backend login to the site or a staging clone site.
The plugin is very good; it works at the indicated values.
We would like also for this plugin to function without authentication for new customers who are placing their first order. Also, if possible, we would like a monitoring value to appear in the cart for obtaining a larger discount. For example, if they have chosen products worth 70 Eur at catalog price, it should also appear in the cart as follows: Add products worth 180 Eur more to obtain a 30% discount. Example 2: If there are products in the cart worth 275 Eur, then it should appear in the cart: Add products worth 175 Eur more to obtain the maximum discount of 40%!
I remind you of the discount levels: a minimum of 50 Eur for a 20% discount, a minimum of 250 Eur for a 30% discount, and a minimum of 450 Eur for a 40% discount
The customer's contact details, phone, email, etc., will be retained from the delivery information. The new customer will immediately receive an email from the company congratulating them on the discount level they have qualified for.
We would like also for this plugin to function without authentication for new customers who are placing their first order.
It is indeed possible to generally allow logged out users to place orders. To do that, just enable this setting here in WooCommerce -> Settings -> Accounts:
I am not sure if there is a way to force users to login after the 1st order, but WooCommerce would notify them if they're using an email that's already registered.
Also, if possible, we would like a monitoring value to appear in the cart for obtaining a larger discount. For example, if they have chosen products worth 70 Eur at catalog price, it should also appear in the cart as follows: Add products worth 180 Eur more to obtain a 30% discount. Example 2: If there are products in the cart worth 275 Eur, then it should appear in the cart: Add products worth 175 Eur more to obtain the maximum discount of 40%!
Configuring these discounts is possible via dynamic rules. However, our plugin does not have a feature for displaying these as you described on the cart page unfortunately.
To do that, some custom coding would be needed to develop the feature and a design that matches your site. While we are not able to do complex customizations directly, generally any WooCommerce developer should be able to help you with that. We would suggest trying to get a quote from a company such as https://codeable.io - we can assist with any technical info needed from our end.
I know it's been a while since I last answered this ticket, but we wanted to know if you could help us modify the custom code below.
On our website, prices can be displayed both in EURO and in LEI. The conversion is done by the FOX CURRENCY SWITHCER module. We have set it so that, on the checkout page, the prices are always displayed LEI - our national currency. As the conversion is done based on the exchange rate of the respective day, the final value of an order may vary.
Can we modify the snippet created by you so that instead of a fixed amount, we put a minimum threshold, meaning that the order must be at least off a certain value to automatically change a user's group? And, considering that the orders are made only in LEI, can we set a minimum value in LEI?
I am not sure if I am understanding this correctly, forgive me if I am missing something as it has been a while.
I understand that you're referring to this snippet I previously shared:
add_action( 'woocommerce_checkout_order_processed', 'b2bking_group_rules_apply', 10, 3 );
add_action( 'woocommerce_blocks_checkout_order_processed', 'b2bking_group_rules_apply', 10, 3 );
function b2bking_group_rules_apply($order_id, $posted_data, $order){
// enter values
$oldgroup_id = 1234;
$newgroup_id = 4567;
$order_threshold = 1000;
// values
$update = false;
$order = wc_get_order($order_id);
$user_id = $order->get_customer_id();
$user_id = b2bking()->get_top_parent_account($user_id);
$order_total = $order->get->total();
$currentusergroupidnr = b2bking()->get_user_group($user_id);
$is_b2b_user = get_user_meta( $user_id, 'b2bking_b2buser', true );
if ($is_b2b_user === 'yes'){
// if $order is above threshold
if ($order_total > $order_threshold){
// if user has old group, update to new group
if ($currentusergroupidnr == $oldgroup_id){
b2bking()->update_user_group($user_id, $newgroup_id);
$update = true;
}
}
}
// delete all b2bking transients
// Must clear transients and rules cache when user group is changed because now new rules may apply.
if ($update){
b2bking()->clear_caches_transients();
b2bking()->b2bking_clear_rules_caches();
}
}
This snippet sets a minimum threshold of 1000, meaning that any order above > 1000 would change the user's group. The order does not have to be exactly (fixed) 1000, any order value above it will work.
And, considering that the orders are made only in LEI, can we set a minimum value in LEI?
If your checkout sets all orders to LEI, that is actually ideal because it means all orders final currency is LEI.
Based on that, you can simply set that "1000" number to a number in LEI and you do not have to worry about its EUR value.
Hi,
Our customers fall into 3 groups depending on the discount they have. We want to create a group-level rule so that customers with a lower discount automatically enter the group with a higher discount if they place an order of a certain value.
Unfortunately, I noticed that we can only choose as a condition the value of the orders from a month, from a year or the total value of all orders.
To qualify for a higher discount level, our customers must make a single order of a certain value. Is it possible to set such a condition?
Thank you.
Hi Givan,
I'd be glad to assist,
Just to make sure I understand this correctly: this cannot be achieved through the total order value setup?
In other words, let's say you want the group change to happen on single orders over $1000.
Does that mean the group should be changed if the customer orders $1000 one time, but should NOT be changed if the customer places 2 orders, of $500 each?
Please let me know. Waiting for your response,
Kind regards,
Stefan
Hi Stefan,
These are the qualification rules for a higher company discount, the customer must place a single order of a certain value and not several cumulative orders.
Can something like this be set with B2BKing?
Thank you.
Hi Givan,
Thank you for clarifying,
There is no default feature for that in B2BKing, but I tried writing a custom code snippet to help you achieve this.
This is the code:
A PHP snippet can be added to functions.php, or by following our guide here: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/
In the code you must set 3 values there at the beginning of the snippet, the order value threshold (e.g. $1000), the old group ID, and the new group ID.
To get a group's ID, you can edit that group in the backend (in b2bking->groups->business group, click on a group), and check the number in the URL. The number in the URL (e.g. ?post=1234) is the ID of the group.
We can help set it up directly on your site if you'd like. For that I'd need a backend login to the site or a staging clone site.
Kind regards,
Stefan
Thank you for the great support!
The plugin is very good; it works at the indicated values.
We would like also for this plugin to function without authentication for new customers who are placing their first order. Also, if possible, we would like a monitoring value to appear in the cart for obtaining a larger discount. For example, if they have chosen products worth 70 Eur at catalog price, it should also appear in the cart as follows: Add products worth 180 Eur more to obtain a 30% discount. Example 2: If there are products in the cart worth 275 Eur, then it should appear in the cart: Add products worth 175 Eur more to obtain the maximum discount of 40%!
I remind you of the discount levels: a minimum of 50 Eur for a 20% discount, a minimum of 250 Eur for a 30% discount, and a minimum of 450 Eur for a 40% discount
The customer's contact details, phone, email, etc., will be retained from the delivery information. The new customer will immediately receive an email from the company congratulating them on the discount level they have qualified for.
Something like this can be done?
Hi Givan,
We would like also for this plugin to function without authentication for new customers who are placing their first order.
It is indeed possible to generally allow logged out users to place orders. To do that, just enable this setting here in WooCommerce -> Settings -> Accounts:
I am not sure if there is a way to force users to login after the 1st order, but WooCommerce would notify them if they're using an email that's already registered.
Also, if possible, we would like a monitoring value to appear in the cart for obtaining a larger discount. For example, if they have chosen products worth 70 Eur at catalog price, it should also appear in the cart as follows: Add products worth 180 Eur more to obtain a 30% discount. Example 2: If there are products in the cart worth 275 Eur, then it should appear in the cart: Add products worth 175 Eur more to obtain the maximum discount of 40%!
Configuring these discounts is possible via dynamic rules. However, our plugin does not have a feature for displaying these as you described on the cart page unfortunately.
To do that, some custom coding would be needed to develop the feature and a design that matches your site. While we are not able to do complex customizations directly, generally any WooCommerce developer should be able to help you with that. We would suggest trying to get a quote from a company such as https://codeable.io - we can assist with any technical info needed from our end.
Kind regards,
Stefan
Hi Stefan,
I know it's been a while since I last answered this ticket, but we wanted to know if you could help us modify the custom code below.
On our website, prices can be displayed both in EURO and in LEI. The conversion is done by the FOX CURRENCY SWITHCER module. We have set it so that, on the checkout page, the prices are always displayed LEI - our national currency. As the conversion is done based on the exchange rate of the respective day, the final value of an order may vary.
Can we modify the snippet created by you so that instead of a fixed amount, we put a minimum threshold, meaning that the order must be at least off a certain value to automatically change a user's group? And, considering that the orders are made only in LEI, can we set a minimum value in LEI?
Thank you.
Givan
Hi Givan,
I am not sure if I am understanding this correctly, forgive me if I am missing something as it has been a while.
I understand that you're referring to this snippet I previously shared:
This snippet sets a minimum threshold of 1000, meaning that any order above > 1000 would change the user's group. The order does not have to be exactly (fixed) 1000, any order value above it will work.
And, considering that the orders are made only in LEI, can we set a minimum value in LEI?
If your checkout sets all orders to LEI, that is actually ideal because it means all orders final currency is LEI.
Based on that, you can simply set that "1000" number to a number in LEI and you do not have to worry about its EUR value.