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.
Opens WPIDE on
Code
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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.