There’s no reason to use add_filter() unless you are modifying someone else’s code or you want someone else to modify your code. If your function needs the user ID as a parameter, you can call your function (called get_total_balance() here) like so:
$id = get_current_user_id();
$balance = get_total_balance( $id );
echo 'Amount owed: ' . money_format('%i', $balance ) . "\n";
Your function declaration, minus the functional code within, would look something like this:
function get_total_balance( $user_id ) {
// take user ID and get their total balance
// assign the balance to variable $bal
return $bal;
}
Thread Starter
Ash
(@ash222)
Hello,
Thanks for the reply. I followed the same structure. I called the function
$balance= wallet_balance($user_id); //here user_id is not of current logged in user. This function is used within the hook woocommerce_order_refunded.
function wallet_balance($user_id){
//my code goes here
}
But in this case i get error. user_id got is empty
Show the code where you get the value you’re passing to the function.
Thread Starter
Ash
(@ash222)
hello,
Sorry for disturbing. Found the answer. You are correct. Mistake I made was didn’t declare wpdb as global variable.
global $wpdb;