php function

Hi i would like to add one function in my website

below is a sample code working for get parent referrer for 2 tier and i need same like 3 tier. how to get parent referrer for 3 tier and 4 tier.

below code explanation is i am A and i refer B (B is my direct referral and when B made any sales i will get commission) now B refer C and C made any sales means B will get commission and also me(A) (2nd tier) also get commission.

Now C refer D and if D made any sales means C will get direct commission and B will get 2nd tier commission and I (A) should get 3rd tier commission and for that i need function help.

Please help.

Regards

function wp_aff_award_second_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email,$buyer_name=’’)
{
global $aff_tx_msg;
$clientdate = (date (“Y-m-d”));
$clienttime = (date (“H:i:s”));

	if (get_option('wp_aff_use_2tier') && !empty($wp_aff_affiliates_db->referrer))
	{
		$aff_tx_msg .= '<br />Using tier model';
		wp_affiliate_log_debug("Using tier model",true);
		$award_tier_commission = true;	
		$duration = get_option('wp_aff_2nd_tier_duration');		
		if(!empty($duration))
		{
			$join_date = $wp_aff_affiliates_db->date;
			$days_since_joined = round((strtotime(date("Y-m-d")) - strtotime($join_date) ) / (60 * 60 * 24));
			
			if ($days_since_joined > $duration)
			{
				$aff_tx_msg .= '<br />Tier commission award duration expried';
				wp_affiliate_log_debug("Tier commission award duration expried! No tier commission will be awarded for this sale.",true);
				$award_tier_commission = false;
			}
		}				
		if ($award_tier_commission)
		{
			if(!empty($wp_aff_affiliates_db->sec_tier_commissionlevel)){
				$second_tier_commission_level = $wp_aff_affiliates_db->sec_tier_commissionlevel;
				wp_affiliate_log_debug("Using the affiliate specific 2nd tier commission for this referral. 2nd tier commission level: ".$second_tier_commission_level,true);
			}
			else{
				$second_tier_commission_level = get_option('wp_aff_2nd_tier_commission_level');
				wp_affiliate_log_debug("Using global 2nd tier commission for this referral. 2nd tier commission level: ".$second_tier_commission_level,true);
			}
			if (get_option('wp_aff_use_fixed_commission'))
			{
                $commission_amount = $second_tier_commission_level;
            }
            else
            {
			    $commission_amount = round(($second_tier_commission_level * $sale_amount)/100,2);
            }
            $campaign_id = "";
            $is_tier_comm = "yes";
			global $wpdb;
			$aff_sales_table = WP_AFF_SALES_TBL_NAME;
			$updatedb = "INSERT INTO $aff_sales_table (refid,date,time,browser,ipaddress,payment,sale_amount,txn_id,item_id,buyer_email,campaign_id,buyer_name,is_tier_comm) VALUES ('$wp_aff_affiliates_db->referrer','$clientdate','$clienttime','','','$commission_amount','$sale_amount','$txn_id','$item_id','$buyer_email','$campaign_id','$buyer_name','$is_tier_comm')";
			$results = $wpdb->query($updatedb);	
			$aff_tx_msg .= '<br />Tier commission awarded to: '.$wp_aff_affiliates_db->referrer.'. Commission amount: '.$commission_amount;
			wp_affiliate_log_debug('Tier commission awarded to: '.$wp_aff_affiliates_db->referrer.'. Commission amount: '.$commission_amount,true);	
		}			
	}	
	return $aff_tx_msg;

}

Just doing a quick glance over the code, I don’t under why you use global $aff_tx_msg (FYI - Global variables in general are bad, if you want the variable have scope pass it by reference) and then you do this return $aff_tx_msg; ? It’s global, it’s going to change anyways…

One last thing, I am so confused I have no idea what you kind of problem your are having, maybe someone else will understand this. All I know is, I’m going to have to take some Advil after reading this. ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service