Advertisement
verygoodplugins

Untitled

Sep 21st, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2.  
  3. function custom_referral_amounts( $referral_amount, $affiliate_id, $amount, $reference, $product_id ) {
  4.  
  5.     $user_id        = affwp_get_affiliate_user_id( $affiliate_id );
  6.     $member         = new MeprUser( $user_id );
  7.     $subscriptions  = array_unique( $member->active_product_subscriptions( 'products' ) );
  8.  
  9.     $user_level = 'freshman';
  10.  
  11.     foreach( $subscriptions as $product ) {
  12.  
  13.         if( strpos($product->post_title, 'Sophomore') !== false ) {
  14.  
  15.             $user_level = 'sophomore';
  16.             break;
  17.  
  18.         } elseif( strpos($product->post_title, 'Junior') !== false ) {
  19.  
  20.             $user_level = 'junior';
  21.             break;
  22.  
  23.         } elseif( strpos($product->post_title, 'Senior') !== false ) {
  24.  
  25.             $user_level = 'senior';
  26.             break;
  27.  
  28.         } elseif( strpos($product->post_title, 'Graduate') !== false ) {
  29.  
  30.             $user_level = 'graduate';
  31.             break;
  32.  
  33.         }
  34.  
  35.     }
  36.  
  37.     // Now we know the user level
  38.  
  39.     if( $user_level == 'freshman' ) {
  40.  
  41.         $referral_amount = $amount * 0.20;
  42.  
  43.         if( $referral_amount > 10 ) {
  44.             $referral_amount = 10;
  45.         }
  46.  
  47.     } elseif( $user_level == 'sophomore' ) {
  48.  
  49.         $referral_amount = $amount * 0.50;
  50.  
  51.         if( $referral_amount > 25 ) {
  52.             $referral_amount = 25;
  53.         }
  54.  
  55.     } elseif( $user_level == 'junior' ) {
  56.  
  57.         $referral_amount = $amount * 0.50;
  58.  
  59.         if( $referral_amount > 100 ) {
  60.             $referral_amount = 100;
  61.         }
  62.  
  63.     } elseif( $user_level == 'senior' ) {
  64.  
  65.         $referral_amount = $amount * 0.50;
  66.  
  67.         if( $referral_amount > 250 ) {
  68.             $referral_amount = 250;
  69.         }
  70.  
  71.     } elseif( $user_level == 'graduate' ) {
  72.  
  73.         $referral_amount = $amount * 0.50;
  74.  
  75.         if( $referral_amount > 500 ) {
  76.             $referral_amount = 500;
  77.         }
  78.  
  79.     }
  80.  
  81.     return $referral_amount;
  82.  
  83. }
  84.  
  85. add_filter( 'affwp_calc_referral_amount', 'custom_referral_amounts', 10, 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement