Disable WooCommerce payment gateways is fairly straight forward once you know what the name of the gateway is. The following code will disable paypal and stripe payment gateways on the WooCommerce checkout page when the cart amount is greater than $1000. You can adjust the code to disable payment gateways based on certain products that are in the cart also.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/* * Disable PayPal payment method in the checkout for a certain cart amount */ add_filter( 'woocommerce_available_payment_gateways', 'es_filter_gateways', 1); function es_filter_gateways( $gateways ){ global $woocommerce; if($woocommerce->cart->total > 1000) { unset($gateways['stripe']); unset($gateways['paypal']); } return $gateways; } |
is there anyway to use this but add something which means it won’t apply if the user has a certain role?
for instance it’ll run for role:customers but not for role:wholesale
Yes you can do that just surround the part that unsets the array with something like this
if( current_user_can('customers')) {
unset($gateways['paypal']);
}
This will remove the PayPal gateway if the logged in user is of type ‘customer’
Hey, thanks for that! Is there any way to disable WooCommerce Payment Gateways when total amount “< 1" or "= 0".
I don't want to show the Payment Gateways when a customer get's free product (because of coupon code).
Thanks
If you checkout this answer on stackoverlow that will help you achieve what you want.
https://stackoverflow.com/questions/46328364/hide-payment-method-based-on-product-type-in-woocommerce
Can this be modified so that when the cart exceeds 82 kg (we have a set limit of 82 kg before we have to manually adjust freight cost) it will hide Stripe as payment method?
Yes it sure can Kristoffer! I’m available for hire if you’d like custom work done.