to preface this I know my way around a computer but I'm no coder by any means. I have a site where users can purchase points/credits to be used for a service on the site. Each customer has their balance displayed in their account in a transactions page, this page gets it's figures from a custom table from what I gather. What I'm essentially trying to do is have the 'remaining balance' figures displayed on each of my users pages, displayed on a single page.

I'm not sure if it's safe to paste the code here.. but if it is I will if it helps. Thanks for taking the time to read this request!

1 Answer 1


Because it is a custom table, you write a custom function: Put this function in your themes functions.php. Then at the position in any template where you want to display the balance: displayRemainingBalance( $currentUserId )

function displayRemainingBalance($userid) {
  global $wpdb;
  $record = $wpdb->get_var($wpdb->prepare('select balance from yourcustomtable WHERE userid=%d', $userid));
echo $record->balance;

You can also use $wpdb->get_results( ... ) to get more than one row, or $wpdb->get_row( ... ) to get one row with multiple fields. The query "select balance from yourcustomtable WHERE userid=%d" depends on what table(s) you have and how you define the loggedin user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.