how to display summary table in affiliate page

Hi, i wish to provide a page on which an affiliate could see his balance only. I have tried the following shortcode [affiliatestatstable]
but it give too much details and many lines in a table i dont want to see. Also this shortcodes doesn't display balance but only debit/credit/payment. In backend we also see balance column and this is the column or information i would like to display for a user. is there other shortcode or something to do for this ?

In short, i wish to display for example :
Balance 100.00$

As a workaround, since i use Gravity form, i could use a form to display data with populated field. But i dont know where to find the balance amount .

  • Tyler Postle

    Hey Sebastian,

    Hope you're doing well today and thanks for your question!

    This will take some custom code to pull that data to the frontend. It is displayed using the $balance variable. Are you familiar with PHP at all?

    The variables are defined in the wp-content/plugins/affiliateincludes/classes/affiliateadmin.php file.

    If you aren't then let us know and I'll flag a developer that will be able to take a closer look at this for you :slight_smile:

    Look forward to hearing back!

    All the best,

  • Jose

    Hey there @Sebastien,

    Thanks for you patience :slight_smile: Hope this is not too late.
    The thread got missed in my queue somehow. I extended you membership for 10 days so that you can get this sorted.

    I coded this shortcode for you. It will return just the balance amount, preceded by the currency.
    It will take 3 parameters, all of them optional.
    If you don't set a period, it will return the historic balance.
    If the user_id is not defined (which would be the most common use) it will use the current logged user id.

    Sample shortocde:
    [affiliateuserbalance currency="CAD" period="201410"]

    This shoould be placed in your functions.php:

    //[affiliateuserbalance currency="USD" period="201410" user_id="1"]
    function affiliateuserbalance_shortcode( $atts ) {
        global $affiliate;
        $attributes = shortcode_atts( array(
            'currency' => 'USD',
            'user_id' => get_current_user_id(),
            'period' => false
        ), $atts );
        $period_clause = "";
            $period_clause = sprintf(" AND period = %s", $attributes['period']);
        $sql_str = $affiliate->db->prepare("SELECT * FROM ". $affiliate->affiliatedata ." WHERE user_id = %d" . $period_clause, $attributes['user_id']);
        $results = $affiliate->db->get_results($sql_str);
        $balance = '0';
        $total_credits = 0;
        $total_debits = 0;
        $total_payments = 0;
        if($results) {
            foreach ($results as $result) {
                $total_credits += $result->credits;
                $total_debits += $result->debits;
                $total_payments += $result->payments;
            $balance = $total_credits - $total_debits - $total_payments;
        return "{$attributes['currency']} " . $balance;
    add_shortcode( 'affiliateuserbalance','affiliateuserbalance_shortcode' );

    Please let me know if this works fine on your end.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.