Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function custom_referral_amounts( $referral_amount, $affiliate_id, $amount, $reference, $product_id ) {
- $user_id = affwp_get_affiliate_user_id( $affiliate_id );
- $member = new MeprUser( $user_id );
- $subscriptions = array_unique( $member->active_product_subscriptions( 'products' ) );
- $user_level = 'freshman';
- foreach( $subscriptions as $product ) {
- if( strpos($product->post_title, 'Sophomore') !== false ) {
- $user_level = 'sophomore';
- break;
- } elseif( strpos($product->post_title, 'Junior') !== false ) {
- $user_level = 'junior';
- break;
- } elseif( strpos($product->post_title, 'Senior') !== false ) {
- $user_level = 'senior';
- break;
- } elseif( strpos($product->post_title, 'Graduate') !== false ) {
- $user_level = 'graduate';
- break;
- }
- }
- // Now we know the user level
- if( $user_level == 'freshman' ) {
- $referral_amount = $amount * 0.20;
- if( $referral_amount > 10 ) {
- $referral_amount = 10;
- }
- } elseif( $user_level == 'sophomore' ) {
- $referral_amount = $amount * 0.50;
- if( $referral_amount > 25 ) {
- $referral_amount = 25;
- }
- } elseif( $user_level == 'junior' ) {
- $referral_amount = $amount * 0.50;
- if( $referral_amount > 100 ) {
- $referral_amount = 100;
- }
- } elseif( $user_level == 'senior' ) {
- $referral_amount = $amount * 0.50;
- if( $referral_amount > 250 ) {
- $referral_amount = 250;
- }
- } elseif( $user_level == 'graduate' ) {
- $referral_amount = $amount * 0.50;
- if( $referral_amount > 500 ) {
- $referral_amount = 500;
- }
- }
- return $referral_amount;
- }
- add_filter( 'affwp_calc_referral_amount', 'custom_referral_amounts', 10, 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement