Last active
July 19, 2016 21:09
-
-
Save ramiabraham/1ca305fe1132dd22ffcaae5cc054eeca to your computer and use it in GitHub Desktop.
Give affiliates one single referral only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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