Created
March 9, 2021 00:30
-
-
Save DeveloperWil/6132d3da57fd5b350cb03425d7406b0c to your computer and use it in GitHub Desktop.
WooCommerce: Set a minimum amount at checkout
This file contains 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 checkout | |
*/ | |
function zpd_wc_minimum_order_amount(): void { | |
/** | |
* $minimum is the minimum value you want to set the checkout total order amount. | |
*/ | |
$minimum = 50; | |
/** | |
* Check the current cart total | |
*/ | |
if ( WC()->cart->total < $minimum ) { | |
if( is_cart() ) { | |
wc_print_notice( | |
sprintf( 'Your current order total is %s - you must have an order with a minimum of %s to place your order ' , | |
wc_price( WC()->cart->total ), | |
wc_price( $minimum ) | |
), 'error' | |
); | |
} else { | |
wc_add_notice( | |
sprintf( 'Your current order total is %s - you must have an order with a minimum of %s to place your order' , | |
wc_price( WC()->cart->total ), | |
wc_price( $minimum ) | |
), 'error' | |
); | |
} | |
} | |
} | |
add_action( 'woocommerce_checkout_process', 'zpd_wc_minimum_order_amount' ); | |
add_action( 'woocommerce_before_cart' , 'zpd_wc_minimum_order_amount' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment