Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* @Title: WooCommerce - Set minimum amount for delivery of an order
* @Author: Mina Pansuriya
* @Blog URL: http://minapansuriya.com/woocommerce-set-minimum-amount-for-delivery-of-an-order/
add_action( 'woocommerce_check_cart_items', 'pbs_cart_check_for_min_order_amount', 99, 1 );
function pbs_cart_check_for_min_order_amount( ) {
global $woocommerce;
// Only check for Cart or Checkout pages
if( is_cart() || is_checkout() ) {
$min_order_amount = 200;
$orderTotal = $woocommerce->cart->total;
if( $orderTotal <= $min_order_amount ) {
// Display our error message
wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>'
.'<br />Current cart\'s total: %s %s',
$min_order_amount,
get_option( 'woocommerce_currency'),
$orderTotal,
get_option( 'woocommerce_currency') ),
'error' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment