I'm using a snippet code from WooCommerce Minimum Order Amount to set a minimum order total by user role.
For the distributors role, I want to change the minimum order total if they have previous order completed.
So for the first order, the minimum would be 3000, for the orders afterward the minimum would become 1000.
Here is my code:
add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// minimum order value by user role
if ( current_user_can('distributors') )
$minimum = 3000;
elseif ( current_user_can('wholesale_customer') )
$minimum = 200;
elseif ( current_user_can('wholesale_vat_exc') )
$minimum = 200;
else
$minimum = 200; // default
if ( WC()->cart->subtotal < $minimum ) {
if( is_cart() ) {
wc_print_notice( sprintf(
'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error' );
} else {
wc_add_notice( sprintf(
'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error' );
}
}
}