rajasekaran1965 Posted September 25, 2014 Share Posted September 25, 2014 (edited) Hi I need to add one more function in my wordpress plugin. below is the sample code working for 2nd tier. Now i need a same function for 3rd and 4th tire. Function explanation I am A and i refer B and if B made any sale means I (A) will get direct commission for that sale. If B refer C and if C made any sale means (B) will get direct commission for that sale. And in this sample code me(A) also get commission for that sale as a 2nd tier. Now C refer D and if D made any sale means © will get direct commission for that sale and (B) will get 2nd tier commission. So here (A) me too should get 3rd tire commission and i need that function. Please help me. 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; } Edited October 12, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/ Share on other sites More sharing options...
QuickOldCar Posted September 25, 2014 Share Posted September 25, 2014 I was interested in this so made a function that produces an array of the tier levels, refer letter, amount remaining each tier after commission deducted, percentage used and commission price Maybe not exactly what you were looking for with your current code, but something you should consider versus trying to keep adding more tiers. If it's something different than you expect, are welcome to modify it. Was interesting to create either way. <?php function referPosition($refer_letter, $amount, $percentage) { //check all parameters exist if (!$refer_letter || !$amount || !$percentage) { return NULL; } //create alphabet array $alphabet = range('a', 'z'); //letter check $refer_letter = strtolower(trim($refer_letter)); if ($refer_letter == '' || !in_array($refer_letter, $alphabet)) { return NULL; } //amount check $amount = str_replace(array( "$", "," ), array( "", "" ), $amount); $amount = number_format($amount, 2, '.', ''); if (trim($amount) <= 0 || !is_numeric($amount)) { return NULL; } //percentage check $percentage = str_replace("%", "", $percentage); if (trim($percentage) <= 0 || !is_numeric($percentage)) { return NULL; } //find array key position of the letter in array, slice it, reverse it $find_key = array_search($refer_letter, $alphabet); $count_position = array_search($find_key, array_keys($alphabet)); //add 1 to count position $count_position = $count_position + 1; $refer_array = array_slice($alphabet, 0, $count_position); $refer_array = array_reverse($refer_array); //loop remaining letters in array and calculate amounts by percentages $commission_array = array(); $deduct = 0; foreach ($refer_array as $key => $value) { $amount = $amount - $deduct; $amount = number_format($amount, 2, '.', ''); $deduct = ($percentage / 100) * $amount; $deduct = number_format($deduct, 2); $tier = $key + 1; $pretty_amount = number_format($amount, 2, '.', ''); //build an array $commission_array[] = array( "tier" => $tier, "letter" => $value, "amount" => $pretty_amount, "percentage" => $percentage, "commission" => $deduct ); //simple single array letter as key and commision_value //$commission_array[$value] = number_format($deduct, 2); } return $commission_array; } /* Usage arguments: letter: works letters a-z upper and lower amount: $ or not, comma or not percentage: % or not all 3 function arguments required or returns null if any arguments do not meet expectations, returns null */ //$payments = referPosition("a", "100", "25%"); //$payments = referPosition("b","$40,000.23","1.5"); //$payments = referPosition("c","$35","5.5"); $payments = referPosition("d","350.20","10%");//letter,amount,percentage //show the array if commission is due if (is_array($payments)) { echo "<pre>"; print_r($payments); echo "</pre>"; } else { echo $payments = 0; } ?> This example returns: Array( [0] => Array ( [tier] => 1 [letter] => d [amount] => 350.20 [percentage] => 10 [commission] => 35.02 ) [1] => Array ( [tier] => 2 [letter] => c [amount] => 315.18 [percentage] => 10 [commission] => 31.52 ) [2] => Array ( [tier] => 3 [letter] => b [amount] => 283.66 [percentage] => 10 [commission] => 28.37 ) [3] => Array ( [tier] => 4 [letter] => a [amount] => 255.29 [percentage] => 10 [commission] => 25.53 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1492095 Share on other sites More sharing options...
QuickOldCar Posted September 26, 2014 Share Posted September 26, 2014 I included the letter that first sold the item $count_position = $count_position + 1; If you want from the letter below it and onwards, just comment out that line. Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1492110 Share on other sites More sharing options...
rajasekaran1965 Posted September 26, 2014 Author Share Posted September 26, 2014 (edited) Hi QuickOldCar, Thank you for your interest in this but actually your code not worked in my program. Just check the below functions. first function is awarding commission for direct referral and second function is awarding commission for 2nd tier referral and third function is added by me for 3rd tier commission but it is not worked bcoz it is not getting the parent referral details. So pleas guide me how to get the parent referral function. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- function wp_aff_award_commission($referrer,$sale_amount,$txn_id,$item_id,$buyer_email,$clientip='',$comm_rate='',$buyer_name='') { global $aff_tx_msg,$aff_error_msg; $commission_award_result = ""; $debug_data = ""; $debug_data .= "Referrer: ".$referrer. ", Sale Amount: ".$sale_amount.", Transaction ID: ".$txn_id.", "; $debug_data .= "Item ID: ".$item_id. ", Buyer Email: ".$buyer_email.", Custom Commission Rate: ".$comm_rate; $aff_tx_msg = $debug_data; wp_affiliate_log_debug($debug_data,true); $clientdate = (date ("Y-m-d")); $clienttime = (date ("H:i:s")); if(empty($clientip)) { $clientip = $_SERVER['REMOTE_ADDR']; } if(empty($txn_id)) { $txn_id = uniqid(); } if (!empty($referrer)) { global $wpdb; $affiliates_table_name = $wpdb->prefix . "affiliates_tbl"; $aff_sales_table = $wpdb->prefix . "affiliates_sales_tbl"; $wp_aff_affiliates_db = $wpdb->get_row("SELECT * FROM $affiliates_table_name WHERE refid = '$referrer'", OBJECT); if(empty($comm_rate)){ $commission_level = $wp_aff_affiliates_db->commissionlevel; } else{ $commission_level = $comm_rate; } if (get_option('wp_aff_use_fixed_commission')) { $commission_amount = $commission_level; } else { $commission_amount = ($commission_level * $sale_amount)/100; } if(WP_AFFILIATE_NO_COMMISSION_FOR_SELF_PURCHASE == '1'){ if(!empty($buyer_email)){ if(wp_aff_check_if_buyer_is_referrer($referrer,$buyer_email)){ wp_affiliate_log_debug('The buyer ('.$buyer_email.') is the referrer ('.$referrer.') so this sale is NOT ELIGIBLE for generating any commission.',true); return true; } } else{ wp_affiliate_log_debug("Buyer email data is missing from the request so the plugin cannot verify the WP_AFFILIATE_NO_COMMISSION_FOR_SELF_PURCHASE option",true); } } $commission_amount = round($commission_amount,2); $c_id=''; if(isset($_COOKIE['c_id'])){ $c_id = $_COOKIE['c_id']; } if(!empty($buyer_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) VALUES ('$referrer','$clientdate','$clienttime','','$clientip','$commission_amount','$sale_amount','$txn_id','$item_id','$buyer_email','$c_id','$buyer_name')"; } else{ $updatedb = "INSERT INTO $aff_sales_table (refid,date,time,browser,ipaddress,payment,sale_amount,txn_id,item_id,buyer_email,campaign_id) VALUES ('$referrer','$clientdate','$clienttime','','$clientip','$commission_amount','$sale_amount','$txn_id','$item_id','$buyer_email','$c_id')"; } $results = $wpdb->query($updatedb); if(!$results) { $aff_tx_msg .= "<br />The database update query failed for table: ".$aff_sales_table; wp_affiliate_log_debug("The database update query failed for table: ".$aff_sales_table,false); } else { $aff_tx_msg .= '<br />The sale has been registered in the WP Affiliate Platform Database for referrer: '.$referrer.' with amount: '.$commission_amount; wp_affiliate_log_debug('The sale has been registered in the WP Affiliate Platform Database for referrer: '.$referrer.' with amount: '.$commission_amount,true); } wp_aff_send_commission_notification($wp_aff_affiliates_db->email,$txn_id); // 2nd tier commission $commission_award_result = wp_aff_award_second_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email,$buyer_name); //This below lines are added by me for tiers 3 to 7 // 3rd tier commission $commission_award_result = wp_aff_award_third_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email,$buyer_name); // 4th tier commission $commission_award_result = wp_aff_award_fourth_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email,$buyer_name); // 5th tier commission $commission_award_result = wp_aff_award_fifth_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email,$buyer_name); // 6th tier commission $commission_award_result = wp_aff_award_sixth_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email,$buyer_name); // 7th tier commission $commission_award_result = wp_aff_award_seventh_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email,$buyer_name); // Up to above i added in this function } return $commission_award_result; } This function is existing and working fine for second tier 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; } This function added by me for 3rd tier but not working function wp_aff_award_third_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_3tier') && !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_3rd_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) { { $third_tier_commission_level = get_option('wp_aff_3rd_tier_commission_level'); wp_affiliate_log_debug("Using global 3rd tier commission for this referral. 3rd tier commission level: ".$third_tier_commission_level,true); } if (get_option('wp_aff_use_fixed_commission')) { $commission_amount = $third_tier_commission_level; } else { $commission_amount = round(($third_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; } ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Please check and find me the solution Edited October 12, 2014 by Ch0cu3r Added code tags Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1492116 Share on other sites More sharing options...
QuickOldCar Posted September 26, 2014 Share Posted September 26, 2014 I wrote what I did so maybe you would do things different, modify as you needed. That's going to be a very large plugin by the time you get to 7 tiers, or even get them to work. I don't see why you can't make the 3rd or any other tier after work similar as in the 2nd tier if that works using similar code. Anyway, my suggestion would be to make everything into one function versus making each tier it's own function. Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1492123 Share on other sites More sharing options...
rajasekaran1965 Posted October 12, 2014 Author Share Posted October 12, 2014 (edited) Hi I need to modify the below code for multiple tiers. Currently it is working for second tier and i need it to extend up to seven tiers. I attached one file which is having function (function mga_create_tier_commissions($sale_id)) for multiple tiers and i need modify like that function in this below code. Please help me. mga_functions.php 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; 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; } 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 leve ".$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; } Edited October 12, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1493398 Share on other sites More sharing options...
QuickOldCar Posted October 12, 2014 Share Posted October 12, 2014 (edited) So the same issue as this post http://forums.phpfreaks.com/topic/291271-wordpress-plugin-help TOPIC MERGED That's why I suggested a function to handle this better and not trying to duplicate mass amounts of code for additional tiers. If my function is not exactly what you need modify or make one that does work for you. Edited October 12, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1493399 Share on other sites More sharing options...
Ch0cu3r Posted October 12, 2014 Share Posted October 12, 2014 @rajasekaran1965 Welcome to PHPFreaks please read the rules regarding posting topics. Duplicate topics are not accepted. I have merged your two topics together. Also please wrap code you paste in to your post between tags or click the <> button in the editor. Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1493406 Share on other sites More sharing options...
rajasekaran1965 Posted October 16, 2014 Author Share Posted October 16, 2014 (edited) So the same issue as this post http://forums.phpfreaks.com/topic/291271-wordpress-plugin-help TOPIC MERGED That's why I suggested a function to handle this better and not trying to duplicate mass amounts of code for additional tiers. If my function is not exactly what you need modify or make one that does work for you. Hi QuickOldCar I am unable to modify the existing function. Can u please modify the function "function wp_aff_award_second_tier_commission" in the attached file. I need to pay upline commissions for up to 7 levels(7tier). Right now it is paying only 2 levels (2 tier). Please help me. filewp_aff_includes.php Edited October 16, 2014 by rajasekaran1965 Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1493809 Share on other sites More sharing options...
QuickOldCar Posted October 16, 2014 Share Posted October 16, 2014 I looked through the mga_functions.php and mga_create_tier_commissions() function mga_create_tier_commissions($sale_id){ global $wpdb; // tiers $tier_commissions = mga_get_setting('tier_commissions'); $tier_levels = mga_get_setting('tier_levels'); // affiliate $affiliate = $wpdb->get_row("SELECT * FROM ".TBL_SALES." WHERE `id`='{$sale_id}'"); // parent $parent_affiliate_id = $wpdb->get_var("SELECT DISTINCT(`parent_affiliate_id`) FROM ".TBL_AFFILITE_TIERS." WHERE `affiliate_id`='{$affiliate->affiliate_id}'"); // loop $level=1; $sub_affiliates=array(); // loop while(intval($parent_affiliate_id)>0){ // next level $level++; // gather all subs $sub_affiliates[$level]=$parent_affiliate_id; // parent $parent_affiliate_id = $wpdb->get_var("SELECT `parent_affiliate_id` FROM ".TBL_AFFILITE_TIERS." WHERE `affiliate_id`='{$parent_affiliate_id}'"); // break if($level==($tier_levels)) break; } // set price if(count($sub_affiliates)>0){ $tier=2; foreach($sub_affiliates as $level=>$parent_affiliate_id){ $commission_amount=($tier_commissions[$tier]/100)*$affiliate->totalprice; $columns =array('affiliate_id' => $parent_affiliate_id, 'click_id' => $affiliate->click_id, 'purchaseid' => $affiliate->purchaseid , 'totalprice' => $affiliate->totalprice, 'commission_amount' => $commission_amount, 'sale_dt' => $affiliate->sale_dt, 'buyer_name' => $affiliate->buyer_name, 'buyer_email' => $affiliate->buyer_email, 'item_type' => 'sales' , 'item_id' => $affiliate->item_id, 'transaction_id' => $affiliate->transaction_id, 'pay_status' => $affiliate->pay_status); // insert $success=$wpdb->insert(TBL_SALES, $columns); $sale_id=$wpdb->insert_id; $tier++; // mail when processed if($affiliate->pay_status=='processed'){ // mail to affiliate mga_mail_notify_affiliate($sale_id); // mail to admin mga_mail_notify_admin($sale_id,'sale'); } } } } From what I see these 2 lines are the only thing stopping the function from doing more levels and tiers I assume this is a global plugins option $tier_levels = mga_get_setting('tier_levels'); then in the while loop if($level==($tier_levels)) break; What happens if comment out those 2 lines? Or make more tier_levels options globally with many additional functions to match. After that you still have all the checks looking for second_tier in wp_aff_award_second_tier_commission() Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1493922 Share on other sites More sharing options...
rajasekaran1965 Posted October 17, 2014 Author Share Posted October 17, 2014 (edited) I looked through the mga_functions.php and mga_create_tier_commissions() function mga_create_tier_commissions($sale_id){ global $wpdb; // tiers $tier_commissions = mga_get_setting('tier_commissions'); $tier_levels = mga_get_setting('tier_levels'); // affiliate $affiliate = $wpdb->get_row("SELECT * FROM ".TBL_SALES." WHERE `id`='{$sale_id}'"); // parent $parent_affiliate_id = $wpdb->get_var("SELECT DISTINCT(`parent_affiliate_id`) FROM ".TBL_AFFILITE_TIERS." WHERE `affiliate_id`='{$affiliate->affiliate_id}'"); // loop $level=1; $sub_affiliates=array(); // loop while(intval($parent_affiliate_id)>0){ // next level $level++; // gather all subs $sub_affiliates[$level]=$parent_affiliate_id; // parent $parent_affiliate_id = $wpdb->get_var("SELECT `parent_affiliate_id` FROM ".TBL_AFFILITE_TIERS." WHERE `affiliate_id`='{$parent_affiliate_id}'"); // break if($level==($tier_levels)) break; } // set price if(count($sub_affiliates)>0){ $tier=2; foreach($sub_affiliates as $level=>$parent_affiliate_id){ $commission_amount=($tier_commissions[$tier]/100)*$affiliate->totalprice; $columns =array('affiliate_id' => $parent_affiliate_id, 'click_id' => $affiliate->click_id, 'purchaseid' => $affiliate->purchaseid , 'totalprice' => $affiliate->totalprice, 'commission_amount' => $commission_amount, 'sale_dt' => $affiliate->sale_dt, 'buyer_name' => $affiliate->buyer_name, 'buyer_email' => $affiliate->buyer_email, 'item_type' => 'sales' , 'item_id' => $affiliate->item_id, 'transaction_id' => $affiliate->transaction_id, 'pay_status' => $affiliate->pay_status); // insert $success=$wpdb->insert(TBL_SALES, $columns); $sale_id=$wpdb->insert_id; $tier++; // mail when processed if($affiliate->pay_status=='processed'){ // mail to affiliate mga_mail_notify_affiliate($sale_id); // mail to admin mga_mail_notify_admin($sale_id,'sale'); } } } } From what I see these 2 lines are the only thing stopping the function from doing more levels and tiers I assume this is a global plugins option $tier_levels = mga_get_setting('tier_levels'); then in the while loop if($level==($tier_levels)) break; What happens if comment out those 2 lines? Or make more tier_levels options globally with many additional functions to match. After that you still have all the checks looking for second_tier in wp_aff_award_second_tier_commission() Hi Thanks for your reply File mga_functions.php is for reference purpose only and i am not using that. I am using wp_aff_includes.php only. I modified the function wp_aff_award_second_tier_commission() like below but not working. Just go through the modification and also please make the correction and help me please. If you want i will send full set if files also. function wp_aff_award_second_tier_commission($txn_id) { global $wpdb; // tiers $is_tier_comm = get_option('wp_aff_use_2tier'); //$tier_levels = get_option('wp_aff_tier_levels'); $tier_levels = "7"; $second_tier_commission_level = get_option('wp_aff_2nd_tier_commission_level'); // parent referrer $parent_referrer = $wpdb->get_var("SELECT DISTINCT(`parent_referrer`) FROM $affiliates_tiers_table_name WHERE `referrer_id`='{$referrer->referrer_id}'"); // loop $level = 1; $sub_affiliates=array(); // loop while(intval($parent_referrer)>0){ // next level $level++; // gather all subs $sub_affiliates[$level] = $parent_referrer; // parent $parent_referrer = $wpdb->get_var("SELECT `parent_referrer` FROM $affiliates_tiers WHERE `referrer_id`='{$parent_referrer}'"); // break if($level==($tier_levels)) break; } // set price if(count($sub_affiliates)>0){ $tier=2; foreach($sub_affiliates as $level=>$parent_referrer){ $commission_amount = round(($second_tier_commission_level * $sale_amount)/100,2); $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); // insert $tier++; } } } Edited October 17, 2014 by rajasekaran1965 Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1493974 Share on other sites More sharing options...
QuickOldCar Posted October 17, 2014 Share Posted October 17, 2014 I'm not making the plugin, maybe someone else will. You should ask the author. Quote Link to comment https://forums.phpfreaks.com/topic/291591-wordpress-plugin-help/#findComment-1494044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.