Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce: Set a minimum amount at checkout
/**
* 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