# Affiliate Earnings Summary Shortcode (AffiliateWP)

> Adds a [wpide_affiliate_stats] shortcode that shows the logged-in affiliate their unpaid and paid earnings, referral count, visits and personal referral link on any page.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: affiliatewp, affiliates, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/affwp-affiliate-stats-shortcode/

## Code

```php
add_shortcode( 'wpide_affiliate_stats', function () {
    if ( ! function_exists( 'affwp_get_affiliate_id' ) || ! is_user_logged_in() ) {
        return '';
    }

    $affiliate_id = affwp_get_affiliate_id( get_current_user_id() );

    if ( ! $affiliate_id || ! affwp_is_active_affiliate( $affiliate_id ) ) {
        return '';
    }

    $rows = array(
        __( 'Unpaid earnings' ) => affwp_get_affiliate_unpaid_earnings( $affiliate_id, true ),
        __( 'Paid earnings' )   => affwp_get_affiliate_earnings( $affiliate_id, true ),
        __( 'Referrals' )       => number_format_i18n( (int) affwp_get_affiliate_referral_count( $affiliate_id ) ),
        __( 'Visits' )          => number_format_i18n( (int) affwp_get_affiliate_visit_count( $affiliate_id ) ),
    );

    $html = '<dl class="wpide-affwp-stats" style="display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:12px">';
    foreach ( $rows as $label => $value ) {
        $html .= '<div style="padding:12px;border:1px solid rgba(0,0,0,.1);border-radius:6px"><dt style="font-size:.85em;opacity:.75">' . esc_html( $label ) . '</dt><dd style="margin:0;font-size:1.4em;font-weight:600">' . wp_kses_post( $value ) . '</dd></div>';
    }
    $html .= '</dl>';

    $url   = affwp_get_affiliate_referral_url( array( 'affiliate_id' => $affiliate_id ) );
    $html .= '<p><label>' . esc_html__( 'Your referral link' ) . '<br><input type="text" readonly value="' . esc_attr( $url ) . '" onclick="this.select()" style="width:100%"></label></p>';

    return $html;
} );
```

## Notes

Visitors who are not active affiliates see nothing; place it on a members page or next to the Affiliate Area.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Affiliate Earnings Summary Shortcode (AffiliateWP)" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
