WooCommerce set minimum cart value limit and add surcharge if Cart value low

By | June 12, 2016

In WooCommerce base online shopping site Some time you or your client would like to set minimum cart value, and add additional surcharge in Cart total if Customer Cart value ( sum of added Item into cart ) is  not equal more than minimum limit.

#
add_action( 'woocommerce_cart_calculate_fees','ls_woocommerce_custom_surcharge' );
function ls_woocommerce_custom_surcharge() {
  global $woocommerce;
	if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return true;
	$minimumprice = 10;
	$currentprice = $woocommerce->cart->cart_contents_total;
	$additionalfee = $minimumprice - $currentprice;
	if($currentprice==0) $additionalfee = -1;
	
	if ( $additionalfee >= 0 ) {
		
		$woocommerce->cart->add_fee( 'Cart Value Adjustment', $additionalfee, true, '' );
		if(is_checkout())
		{
			$lsmin = wc_price( $minimumprice );
			$lscp = wc_price( $currentprice );
			wc_add_notice(
		    sprintf( 'Minimum Cart value is %s per order. As your current Cart only %s, an additional fee will be applied at checkout.' ,
		        $lsmin,
		        $lscp
		    ), 'success'
			);
		}
		else
		{
			wc_print_notice(
		    sprintf( 'Minimum Cart value is %s per order. As your current Cart only %s, an additional fee will be applied at checkout.' ,
		        wc_price( $minimumprice ),
		        wc_price( $currentprice )
		    ), 'error'
			);
		}
	}
}

Add Vat or Other Specific Charge as Additional Charge

add_action( 'woocommerce_cart_calculate_fees','ls_woocommerce_custom_surcharge' );
function ls_woocommerce_custom_surcharge() {
  global $woocommerce;
	if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return true;
	$percent = 18;
	$vatfees = ($woocommerce->cart->cart_contents_total * $percent ) / 100 ;
				
	if ( $vatfees >= 0 ) {
		
		$woocommerce->cart->add_fee( 'Vat', $vatfees, true, '' );
	}
}

Useful link
Minimum order amount in Woocommerce
Add a surcharge to cart and checkout – uses fees API