# Notify Affiliates When a Referral Is Paid (AffiliateWP)

> Emails an affiliate a short thank-you when one of their referrals is marked as paid, with the amount, which keeps partners motivated between payouts.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: affiliatewp, email, referrals
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/affwp-notify-on-paid-referral/

## Code

```php
add_action( 'affwp_set_referral_status', function ( $referral_id, $new_status, $old_status ) {
    if ( 'paid' !== $new_status || 'paid' === $old_status || ! function_exists( 'affwp_get_referral' ) ) {
        return;
    }

    $referral  = affwp_get_referral( $referral_id );
    $affiliate = $referral ? affwp_get_affiliate( $referral->affiliate_id ) : false;
    $user      = $affiliate ? get_userdata( $affiliate->user_id ) : false;

    if ( ! $user ) {
        return;
    }

    wp_mail(
        $user->user_email,
        sprintf( '[%s] Your commission has been paid', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ),
        sprintf(
            "Hi %1\$s,\n\nGood news: your commission of %2\$s for referral #%3\$d has been paid.\n\nThank you for sending customers our way!\n",
            $user->first_name ? $user->first_name : $user->display_name,
            html_entity_decode( affwp_currency_filter( affwp_format_amount( $referral->amount ) ) ),
            $referral_id
        )
    );
}, 10, 3 );
```

## Notes

Sent once per referral when its status changes to paid.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Notify Affiliates When a Referral Is Paid (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/
