I tried to make the code to do this, but it ended up breaking my site. Can you help correct the code I’ve made?
//remove payment via transfer if customer has credit available//
add_filter( 'woocommerce_available_payment_gateways', 'unset_gateway_if_credit_available' );
function unset_gateway_if_credit_available( $available_gateways ) {
if ( is_admin() ) return $available_gateways;
if ( ! is_checkout() ) return $available_gateways;
$unset = false;
$current_wallet_amount = apply_filters( 'woo_wallet_partial_payment_amount', woo_wallet()->wallet->get_wallet_balance( get_current_user_id(), 'edit' ) );
$rest_amount = get_woowallet_cart_total () - $current_wallet_amount;
$current_cart_total = WC()->cart->cart_contents_total;
if ( $rest_amount >= $current_cart_total ) {
$unset = true;;
break;
}
if ( $unset == true ) unset( $available_gateways['bcas'] );
return $available_gateways;
}