Set Minimum Order Amount in Woocommerce, but Still Allow Checkout by Forcing a Minimum Price

There are a lot of snippets out there, even plugins, to force a minimum order amount in Woocommerce. However, these all force the user to purchase something else before they can checkout.

If they don’t want to make an additional purchase, or perhaps if it’s impossible for them to do so for whatever reason, then they can’t checkout.

The following checks that they meet a minimum order amount and, if they don’t, adds a fee so that their order is that minimum amount. That way, they can still checkout, they just have to pay the full minimum order amount.

Note that this does not work if you’re using the Subscriptions add on.

Update: The original code block (shown at the end of this post) still works, but this is much neater:

add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$minimumprice = 25;
$currentprice = $woocommerce->cart->cart_contents_total;
$additionalfee = $minimumprice - $currentprice;
if ( $additionalfee >= 0 ) {
wc_print_notice(
sprintf( 'We have a minimum %s per order. As your current order is only %s, an additional fee will be applied at checkout.' ,
wc_price( $minimumprice ),
wc_price( $currentprice )
), 'error'
);
$woocommerce->cart->add_fee( 'Minimum Order Adjustment', $additionalfee, true, '' );
}
}
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
add_action( 'woocommerce_cart_calculate_fees' , 'wc_minimum_order_amount' );

function wc_minimum_order_amount() {
global $woocommerce;
global $order;
// Set this variable to specify a minimum order value
$minimum = 25;
if ( WC()->cart->total < $minimum ) { wc_print_notice( sprintf( 'We have a minimum %s per order. As your current order is only %s, an additional fee will be applied at checkout.' , wc_price( $minimum ), wc_price( WC()->cart->total )
), 'error'
);
$currentcarttotal = $woocommerce->cart->get_cart_total();
$killone = '$';
$killtwo = '
';
$currentcarttotal = explode($killone, $currentcarttotal);
$currentcarttotal = $currentcarttotal[1];
$additionalfee = $minimum - $currentcarttotal;
$woocommerce->cart->add_fee( __('Minimum Order Amount Adjustment ', 'woocommerce'), $additionalfee );
}
}

Up Next: Add Fees to a Woocommerce Cart Based on Shipping Class