• Resolved caybridge

    (@caybridge)


    I am testing the following shortcode to add credit programmatically. The wallet balance is updated but the transaction table registered the credit twice so, ultimately, the balance has twice the amount. Please I’ll appreciate your help.

    // Test Shortcode
    function testsc_shortcode() {
    $user_id = get_current_user_id();
    $amount = 18;
    $payment_type = ‘credit’;
    // $payment_type = ‘debit’;

    $description = ‘Testing’;

    // $amount = apply_filters( ‘woo_wallet_addjust_balance_amount’, number_format( $amount, wc_get_price_decimals(), ‘.’, ” ), $user_id );
    if ( ‘credit’ === $payment_type) {
    $transaction_id = woo_wallet()->wallet->credit( $user_id, $amount, $description);
    } else if ( ‘debit’ === $payment_type) {
    $transaction_id = woo_wallet()->wallet->debit( $user_id, $amount, $description);
    }

    $abc = woo_wallet()->wallet->get_wallet_balance( $user_id );

    return ($abc);

    }
    add_shortcode(‘testsc’, ‘testsc_shortcode’);

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

    (@subratamal)

    Hi @caybridge

    Please use below updated code.

    // Test Shortcode
    function testsc_shortcode() {
        if(is_admin()){
            return;
        }
        $user_id = get_current_user_id();
        $amount = 18;
        $payment_type = 'credit';
        // $payment_type = ‘debit’;
    
        $description = 'Testing';
    
        // $amount = apply_filters( ‘woo_wallet_addjust_balance_amount’, number_format( $amount, wc_get_price_decimals(), ‘.’, ” ), $user_id );
        if ('credit' === $payment_type) {
            $transaction_id = woo_wallet()->wallet->credit($user_id, $amount, $description);
        } else if ('debit' === $payment_type) {
            $transaction_id = woo_wallet()->wallet->debit($user_id, $amount, $description);
        }
    
        $abc = woo_wallet()->wallet->get_wallet_balance($user_id);
    
        return ($abc);
    }
    
    add_shortcode('testsc', 'testsc_shortcode');

    Thank you.

    Thread Starter caybridge

    (@caybridge)

    Hi Subrata,

    I used the code you added above (which has no difference to the one I sent you) and the problem persists! The transaction is added twice in My Account.

    Please I’ll appreciate your help on that.

    Thanks!

    Plugin Author Subrata Mal

    (@subratamal)

    The code is not the same there is checking with

    if(is_admin()){
        return; 
    }
    Thread Starter caybridge

    (@caybridge)

    Thanks for your prompt reply. The problem is not related to the Admin. The problem is that the transaction is registered twice so if the user added $10 their account shows $20 (two transactions of $10 each). I check the transactions at the user level in the Woocommerce My Account ==> My Wallet page. I’ll send you the screen shot by email.
    By the way, when I add funds to the user through the Admin (through the Tera Wallet option) everything works fine! It is only through the shortcode.
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Transactions registered twice’ is closed to new replies.