Ok, after a bit more work, I’ve solved this and figured I would share it with others looking for the same solution. This code will hide other payment methods if their balance is higher than the available credit, and then show the payment methods again if their balance is lower than the cart total. I had to take into account the shipping, fees, taxes, and subtotal.
if(!function_exists('dwd_woo_wallet_woocommerce_available_payment_gateways')){
function dwd_woo_wallet_woocommerce_available_payment_gateways($availableGateways){
$customerWallet = woo_wallet()->wallet->get_wallet_balance('', 'edit');
$customerCartTotal = WC()->cart->subtotal;
$chosenMethods = WC()->session->get( 'chosen_shipping_methods' );
$chosenPaymentMethod = WC()->session->get( 'chosen_payment_method' );
$chosenShipping = $chosenMethods[0];
$shippingCost = number_format(WC()->cart->shipping_total, 2, '.', '');
$shippingCost = (float)$shippingCost;
$cartFees = WC()->cart->get_fees();
foreach ($cartFees as $cartFee => $feekKey) {
foreach ($feekKey as $feekKey => $feeData) {
if ($feekKey == 'total') {
if ($feeData > 0) {
$totalFee= $feeData;
}
}
}
}
$cartTaxes = WC()->cart->get_taxes_total();
if(!is_admin() && !is_wallet_rechargeable_cart() && (($customerCartTotal + $shippingCost + $totalFee + $cartTaxes) <= $customerWallet)){
foreach ($availableGateways as $id => $gateway){
if('wallet' != $id){
unset($availableGateways[$id]);
}
}
}
return $availableGateways;
}
}
add_filter('woocommerce_available_payment_gateways', 'dwd_woo_wallet_woocommerce_available_payment_gateways');