Created
July 13, 2016 17:34
-
-
Save scottbuscemi/64211d3fd582ba2d55ef5c3977465c14 to your computer and use it in GitHub Desktop.
WooCommerce minimum order amount for subtotal only (don't include shipping+tax)
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
// Add to your functions.php file | |
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' ); | |
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); | |
function wc_minimum_order_amount() { | |
// Set this variable to specify a minimum order value | |
$minimum = 50; | |
if ( WC()->cart->subtotal < $minimum ) { | |
if( is_cart() ) { | |
wc_print_notice( | |
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' , | |
wc_price( $minimum ), | |
wc_price( WC()->cart->subtotal ) | |
), 'error' | |
); | |
} else { | |
wc_add_notice( | |
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' , | |
wc_price( $minimum ), | |
wc_price( WC()->cart->subtotal ) | |
), 'error' | |
); | |
} | |
} | |
} |
Awesome stuff, thanks for the help
Just so you know, it causes issues with Braintree, won't allow me to enter my card details.
This method seems to work. Rather than calling the two hooks:
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
Use this instead:
add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );
It will stop you reaching the checkout unless purchase requirement is met
Quick question:
How do i apply to this to international orders only. E.g. orders from America and canada I want to have it as minimum of 20 items need to be ordered. However for Australia have no minimum requirements?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yes it works.thanks