Minimum Order Amount for Wholesale Customers
Requires trade customers to reach a higher minimum order value than retail shoppers before they can check out.
Opens WPIDE on
Code
$wpide_trade_minimum = array(
'roles' => array( 'wholesale_customer' ), // Roles with the minimum.
'amount' => 250, // Minimum subtotal.
);
add_action( 'woocommerce_check_cart_items', function () use ( $wpide_trade_minimum ) {
if ( ! is_user_logged_in() || ! array_intersect( $wpide_trade_minimum['roles'], (array) wp_get_current_user()->roles ) ) {
return;
}
$subtotal = (float) WC()->cart->get_subtotal();
if ( $subtotal < $wpide_trade_minimum['amount'] ) {
wc_add_notice(
sprintf( 'Trade orders have a minimum of %1$s. Your cart is currently %2$s.', wc_price( $wpide_trade_minimum['amount'] ), wc_price( $subtotal ) ),
'error'
);
}
} );
Notes
The minimum is compared with the cart subtotal before shipping, and retail customers are not affected.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.