Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter kmalber

    (@kmalber)

    Thanks Michael. I can try that. Unfortunately, I am reliant on Ultimate Member which I have customized significantly with additional code. I suspect it might be that custom code which is the culprit, but wondered if anyone else had successfully used this plugin with vanilla Ultimate Member to narrow my focus. Entirely likely I may have to custom code my own solution here.

    Thread Starter kmalber

    (@kmalber)

    Will do. Have a wonderful day.

    Thread Starter kmalber

    (@kmalber)

    Many thanks for your quick attention and reply. Just updated and all looks good.

    Thread Starter kmalber

    (@kmalber)

    Thanks Subrata. In case it helps anyone else, here’s the code I’m using:

    add_filter('woo_wallet_is_enable_top_up', 'ka_limit_topup_to_neg_bal');
    
    function ka_limit_topup_to_neg_bal($enable_flag){
    
        $user = wp_get_current_user();      
    
        $current_user_id = $user->ID;
    
        $wallet_bal =  woo_wallet()->wallet->get_wallet_balance($current_user_id, ''); 
    
        $enable_flag = FALSE;    //initialize to not allow top_up unless debit balance
    
    // if a debit balance exists, allow payment
    
        if ($wallet_bal<0) {
    
            $enable_flag = TRUE;
    
        } 
    
        return $enable_flag;        
    
    }
    Thread Starter kmalber

    (@kmalber)

    Worked like a charm! Thank you so much for your help Subrata.

    Thread Starter kmalber

    (@kmalber)

    I think I may have figured it out. I amended the code to add a wc_clear_notices() prior to the wc_add_notice (code below). This appears to be working. Would you know if there is any reason which would counter-indicate using this method (eg could there be situations where there are stored notices besides this one error message that I wouldn’t want to clear)? Thanks so much for your help.

    add_filter(‘woocommerce_add_to_cart_validation’, ‘ka_neg_balance_msg’, 20);

    function ka_neg_balance_msg($valid ){
    $product = get_wallet_rechargeable_product();
    if ( is_wallet_rechargeable_cart() ) {
    wc_clear_notices();
    wc_add_notice( apply_filters( ‘woo_wallet_restrict_other_from_add_to_cart’, __( ‘NEW MESSAGE WORDING’, ‘woo-wallet’ ) ), ‘error’ );
    $valid = false;
    }
    return $valid;
    }`

    Thread Starter kmalber

    (@kmalber)

    Thank you both so much for your quick reply. I am relatively new to this and hope you might be able to provide a little more direction as to how to use the plugin filter. I have investigated the woo-wallet front end code to see where the filter function is defined and the hook at which it is added. I tried copying the function code into my function.php, modifying it to include my preferred message wording and hooking it to the same hook used in the front end code. The result is that the new error message is appended to the default message. Would you be able to instruct as to how I might instead remove the default message and replace it with my preferred text? Any help you could give would be most gratefully appreciated!

    add_filter(‘woocommerce_add_to_cart_validation’, ‘ka_neg_balance_msg’, 20);

    function ka_neg_balance_msg($valid ){
    $product = get_wallet_rechargeable_product();
    if ( is_wallet_rechargeable_cart() ) {
    wc_add_notice( apply_filters( ‘woo_wallet_restrict_other_from_add_to_cart’, __( ‘NEW MESSAGE WORDING’, ‘woo-wallet’ ) ), ‘error’ );
    $valid = false;
    }
    return $valid;
    }`

Viewing 7 replies - 1 through 7 (of 7 total)