Created
July 12, 2022 10:11
-
-
Save LeMiira/4b73f557037da4de54d2fdd56ca2ac21 to your computer and use it in GitHub Desktop.
Set min amount on woocommerce
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
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