Skip to content

Instantly share code, notes, and snippets.

@malsubrata
Created June 29, 2018 10:21
Show Gist options
  • Save malsubrata/674f220ef3e9ef6beb03dcab31c26c6e to your computer and use it in GitHub Desktop.
Save malsubrata/674f220ef3e9ef6beb03dcab31c26c6e to your computer and use it in GitHub Desktop.
add_filter('woo_wallet_current_balance', 'woo_wallet_current_balance', 10, 2);
if(!function_exists('woo_wallet_current_balance')){
function woo_wallet_current_balance($balance, $user_id){
$credit_amount = array_sum(wp_list_pluck(get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'credit')), 'nocache' => true)), 'amount'));
$debit_amount = array_sum(wp_list_pluck(get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'debit')), 'nocache' => true)), 'amount'));
$balance = $credit_amount - $debit_amount;
return $balance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment