Last active
February 9, 2018 15:55
-
-
Save pattikawa/e18a21d66cd1f9e09b2bed3857e4238c to your computer and use it in GitHub Desktop.
Woocommerce: Set a minimum amount for order outside your country before checking out
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
// Set a minimum amount for order outside Indonesia before checking out | |
add_action( 'woocommerce_check_cart_items', 'cw_min_num_products' ); | |
// Only run in the Cart or Checkout pages | |
function cw_min_num_products() { | |
if( is_cart() || is_checkout() ) { | |
global $woocommerce; | |
// Set the minimum order amount and your country shipping zone before checking out | |
$minimum = 50; | |
$country = array('ID'); | |
// Defining var total amount | |
$cart_tot_order = WC()->cart->total; | |
// Compare values and add an error in Cart's total amount | |
// happens to be less than the minimum required before checking out. | |
// Will display a message along the lines | |
if( $cart_tot_order < $minimum && !in_array( WC()->customer->get_shipping_country(), $country ) ) { | |
// Display error message | |
wc_add_notice( sprintf( '<strong>A Minimum order of $%s is required before checking out.</strong>' | |
. '<br />Current order: $%s.', | |
$minimum, | |
$cart_tot_order ), | |
'error' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
check this for country ID
https://gist.github.com/josephilipraja/8341837#gistcomment-2346540