[insert_php]

global $wpdb;
global $mbsy;

$query = “select `um`.* from `wur_users` as `us` inner join `wur_usermeta` as `um` on `us`.`id` = `um`.`user_id`
where meta_key = ‘_omniwp_ambassador_data'”;

$result = $wpdb->get_results($query);
$i=1;
$reference = array();
foreach($result as $key=>$val)
{
$individual = unserialize($val->meta_value);
$ref = $individual[‘referring_email’];
if($ref)
{
$reference[$ref] = 1;
$i++;
}
}

//print_R($reference);

foreach($reference as $key=>$val)
{
$data = array(’email’ => $key);
$response_raw = $mbsy->get_ambassador_stats( $data );
$response = json_decode($response_raw );
$name = $response->response->data->ambassador->first_name;
$total_credits = $response->response->data->ambassador->campaign_links[0]->stats->commissions->approved_sum;
$key = $key.”,”.$name;
$newreference[$key] = $total_credits;
}
arsort($newreference);
echo “

“;
$i=1;
foreach($newreference as $key=>$val)
{
$ambassador_data = explode( ‘,’, $key);
$ambassador_name = $ambassador_data[1];
echo “

“;
$i++;
}
echo “
S.no. Name Amount
“.$i.” “.$ambassador_name.” “.$val.”

“;
[/insert_php]

Leave a Reply

Your email address will not be published. Required fields are marked *