Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeveloperWil/6132d3da57fd5b350cb03425d7406b0c to your computer and use it in GitHub Desktop.
Save DeveloperWil/6132d3da57fd5b350cb03425d7406b0c to your computer and use it in GitHub Desktop.
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