I want to restrict buyers to pay via BACS only for high value items e.g. more than 99. I've come up with following code but it doesn't hide card payment. I'm not sure if card
is the correct value in $available_gateways['card']
for WooPayments - Credit card / debit card method?
How to correct it?
functions.php
//////////// Restrict payment option to be BACS for high value items
add_filter('woocommerce_available_payment_gateways', 'restrict_bacs_for_high_value_items', 99, 1);
function restrict_bacs_for_high_value_items( $available_gateways ) {
global $product;
if ( is_admin() ) return $available_gateways; // Only on frontend
$product_price = round($product->price);
if ( isset($available_gateways['card']) && ($product_price > 99) ) {
unset($available_gateways['card']);
}
return $available_gateways;
}
The following code will restrict payments methods to BACS (bank wire) only if a high value item is in cart (product with a price up to 100):
Code goes in functions.php file of your child theme (or in a plugin). Tested and works.