Skip to content

Instantly share code, notes, and snippets.

@ramiabraham
Last active July 19, 2016 21:09
Show Gist options
  • Select an option

  • Save ramiabraham/1ca305fe1132dd22ffcaae5cc054eeca to your computer and use it in GitHub Desktop.

Select an option

Save ramiabraham/1ca305fe1132dd22ffcaae5cc054eeca to your computer and use it in GitHub Desktop.
Give affiliates one single referral only.
<?php
/**
* Plugin Name: AffiliateWP - First Referral Commission Only
* Plugin URI: https://affiliatewp.com
* Description: Modify an affiliate's commission rate for their very first referral. All other subsequent referrals will be recorded at zero.
* Author: ramiabraham
* Author URI: https://affiliatewp.com
* Version: 1.0
*/
/**
* Give the affiliate a $5 commission, but only for their very first referral.
*/
function affwp_first_ref_gets_five_else_zilch( $referral_amount, $affiliate_id, $amount, $reference, $product_id ) {
// get the affiliate's referrals
$referrals = affiliate_wp()->referrals->get_referrals( array( 'affiliate_id' => $affiliate_id ) );
// if they haven't made a referral before, give them $5.00.
if ( empty( $referrals ) ) {
$referral_amount = 5.00;
} else {
$referral_amount = 0.00;
}
return $referral_amount;
}
add_filter( 'affwp_calc_referral_amount', 'affwp_first_ref_gets_five_else_zilch', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment