Created
January 25, 2017 04:32
-
-
Save MinaPansuriya/a349fa2d569598e50ddde2a9ba952bda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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