• Resolved ohdearbambi

    (@ohdearbambi)


    Hello,

    Is it possible to hide certain payment methods, in this case payment method via bank transfer (bcas) when the user still has enough credit in their wallet?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Subrata Mal

    (@subratamal)

    @ohdearbambi Yes, you can hide payment methods using the WooCommerce filter woocommerce_available_payment_gateways.

    Thread Starter ohdearbambi

    (@ohdearbambi)

    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;
    }
    
    Plugin Author Subrata Mal

    (@subratamal)

    @ohdearbambi Please try this code.

    if(!function_exists('woocommerce_available_payment_gateways_callback')){
        function woocommerce_available_payment_gateways_callback($_available_gateways){
            if(!is_admin() && !is_wallet_rechargeable_cart() && is_full_payment_through_wallet()){
                foreach ($_available_gateways as $id => $gateway){
                    if('wallet' != $id){
                        unset($_available_gateways[$id]);
                    }
                }
            }
            return $_available_gateways;
        }
    }
    add_filter('woocommerce_available_payment_gateways', 'woocommerce_available_payment_gateways_callback');
    Thread Starter ohdearbambi

    (@ohdearbambi)

    It works perfectly! Thanks so much for the help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hide payment via bank transfer if user has credit in wallet?’ is closed to new replies.