1. Home
  2. Knowledge Base
  3. WooCommerce Wholesale Prices Premium
  4. Minimum Requirements
  5. How To Set A Lower Minimum Threshold Or Lower Wholesale Prices For The First Order

How To Set A Lower Minimum Threshold Or Lower Wholesale Prices For The First Order

When your wholesale customer first signs up you may wish to provide them with some incentive pricing on their first order.

This can take many forms such as:

The following code snippet lets you change the wholesale user role to a different user role after the first order.

For this to work, you need WooCommerce Wholesale Prices Premium and must create a new wholesale role under WooCommerce->Wholesale Roles called “Wholesale First Order” with the slug “wholesale_first_order”.

With the WooCommerce Wholesale Lead Capture plugin you can automatically set the desired wholesale user role on registration approval. So if you’re using this plugin, also remember to change this setting to point to your new Wholesale First Order user role.

Here’s the code to add to your functions.php:

function wwsChangeUserRoleAfterFirstOrder( $order_id ) {
if ( !isset( $order_id ) )
return;

 $old_role = 'wholesale_first_order';
 $new_role = 'wholesale_customer';
 $order = new WC_Order( $order_id );
 $order_user_id = $order->get_user_id();
 $order_user = new WP_User( $order_user_id );

// If user is not a guest
if ( $order_user ) {
// If the user is sitting at 1 or more orders and the user has the old
// user role, then change the user role to the new role
if ( in_array( $old_role, $order_user->roles ) && 
  wc_get_customer_order_count($order_user->ID) >= 1) {
  wp_update_user( array(
  'ID' => $order_user->ID,
  'role' => $new_role
  ) );
 }
}

}

add_action( 'woocommerce_order_status_completed', 'wwsChangeUserRoleAfterFirstOrder', 10, 1 );

Explanation: On Order completion, checks the Customer attached to the Order to see if they have the “Wholesale First Order” user role and if they also have 1 or more Orders in the system.

If this is the case then it changes the Customer’s role to the “Wholesale Customer” user role.

You can tweak the user role names in the code above and you could even increase the Order count if you wish (you might only want to change them over after 10 orders for instance).

NOTE: Now that you have two Wholesale user roles you will need to fill in wholesale pricing for both wholesale roles so the first user role sees the correct wholesale pricing as well.

This also opens up the door to change the wholesale minimum thresholds for this user role as well (either the Order thresholds or the individual Product minimum quantity thresholds).

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support
Complete Your Purchase