Skip to content

Instantly share code, notes, and snippets.

@LeMiira
Created July 12, 2022 10:11
Show Gist options
  • Save LeMiira/4b73f557037da4de54d2fdd56ca2ac21 to your computer and use it in GitHub Desktop.
Save LeMiira/4b73f557037da4de54d2fdd56ca2ac21 to your computer and use it in GitHub Desktop.
Set min amount on woocommerce
function disablegateways( $gateways ) {
if( is_admin() ) {
return $gateways;
}
if ( isset( $gateways[ 'stripe' ] ) ) {
unset( $gateways[ 'stripe' ] );
}
if ( isset( $gateways[ 'paypal' ] ) ) {
unset( $gateways[ 'paypal' ] );
}
var_dump($gateways);
die();
return $gateways;
}
/**
* Set a minimum order amount for checkout
*/
add_action( 'woocommerce_before_checkout_form', '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 = 25;
$total=WC()->cart->total - WC()->cart->shipping_total ;
if ( $total < $minimum ) {
add_filter( 'woocommerce_available_payment_gateways', 'disablegateways' );
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($total),
wc_price( $minimum )
), 'error'
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment