Ejemplo n.º 1
0
 /**
  * Get the data being exported
  *
  * @access public
  * @since 1.3
  * @return array $data Data for Export
  */
 public function get_data()
 {
     $args = array('status' => $this->status, 'number' => -1);
     $data = array();
     $affiliates = affiliate_wp()->affiliates->get_affiliates($args);
     if ($affiliates) {
         foreach ($affiliates as $affiliate) {
             $data[] = array('affiliate_id' => $affiliate->affiliate_id, 'email' => affwp_get_affiliate_email($affiliate->affiliate_id), 'payment_email' => affwp_get_affiliate_payment_email($affiliate->affiliate_id), 'username' => affwp_get_affiliate_login($affiliate->affiliate_id), 'rate' => affwp_get_affiliate_rate($affiliate->affiliate_id), 'rate_type' => affwp_get_affiliate_rate_type($affiliate->affiliate_id), 'earnings' => $affiliate->earnings, 'referrals' => $affiliate->referrals, 'visits' => $affiliate->visits, 'status' => $affiliate->status, 'date_registered' => $affiliate->date_registered);
         }
     }
     $data = apply_filters('affwp_export_get_data', $data);
     $data = apply_filters('affwp_export_get_data_' . $this->export_type, $data);
     return $data;
 }
 /**
  * Get the data being exported
  *
  * @access public
  * @since 1.0
  * @return array $data Data for Export
  */
 public function get_data()
 {
     $args = array('status' => 'unpaid', 'date' => !empty($this->date) ? $this->date : '', 'number' => -1);
     // Final data to be exported
     $data = array();
     // The affiliates that have earnings to be paid
     $affiliates = array();
     // The list of referrals that are possibly getting marked as paid
     $to_maybe_pay = array();
     // Retrieve the referrals from the database
     $referrals = affiliate_wp()->referrals->get_referrals($args);
     // The minimum payout amount
     $minimum = !empty($_POST['minimum']) ? sanitize_text_field(affwp_sanitize_amount($_POST['minimum'])) : 0;
     if ($referrals) {
         foreach ($referrals as $referral) {
             if (in_array($referral->affiliate_id, $affiliates)) {
                 // Add the amount to an affiliate that already has a referral in the export
                 $amount = $data[$referral->affiliate_id]['amount'] + $referral->amount;
                 $data[$referral->affiliate_id]['amount'] = $amount;
             } else {
                 $email = affwp_get_affiliate_email($referral->affiliate_id);
                 $data[$referral->affiliate_id] = array('email' => $email, 'amount' => $referral->amount, 'currency' => !empty($referral->currency) ? $referral->currency : affwp_get_currency());
                 $affiliates[] = $referral->affiliate_id;
             }
             // Add the referral to the list of referrals to maybe payout
             if (!array_key_exists($referral->affiliate_id, $to_maybe_pay)) {
                 $to_maybe_pay[$referral->affiliate_id] = array();
             }
             $to_maybe_pay[$referral->affiliate_id][] = $referral->referral_id;
         }
         // Now determine which affiliates are above the minimum payout amount
         if ($minimum > 0) {
             foreach ($data as $affiliate_id => $payout) {
                 if ($payout['amount'] < $minimum) {
                     unset($data[$affiliate_id]);
                     unset($to_maybe_pay[$affiliate_id]);
                 }
             }
         }
         // We now know which referrals should be marked as paid
         foreach ($to_maybe_pay as $referral_list) {
             foreach ($referral_list as $referral_id) {
                 affwp_set_referral_status($referral_id, 'paid');
             }
         }
     }
     $data = apply_filters('affwp_export_get_data', $data);
     $data = apply_filters('affwp_export_get_data_' . $this->export_type, $data);
     return $data;
 }
 /**
  * Get the data being exported
  *
  * @access public
  * @since 1.0
  * @return array $data Data for Export
  */
 public function get_data()
 {
     $args = array('status' => $this->status, 'date' => !empty($this->date) ? $this->date : '', 'affiliate_id' => $this->affiliate, 'number' => -1);
     $data = array();
     $affiliates = array();
     $referral_ids = array();
     $referrals = affiliate_wp()->referrals->get_referrals($args);
     if ($referrals) {
         foreach ($referrals as $referral) {
             $data[] = array('affiliate_id' => $referral->affiliate_id, 'email' => affwp_get_affiliate_email($referral->affiliate_id), 'payment_email' => affwp_get_affiliate_payment_email($referral->affiliate_id), 'amount' => $referral->amount, 'currency' => $referral->currency, 'campaign' => $referral->campaign, 'reference' => $referral->reference, 'context' => $referral->context, 'status' => $referral->status, 'date' => $referral->date);
         }
     }
     $data = apply_filters('affwp_export_get_data', $data);
     $data = apply_filters('affwp_export_get_data_' . $this->export_type, $data);
     return $data;
 }
/**
 * Plugin Name: AffiliateWP - Email Affiliate When Referral Paid
 * Plugin URI: http://affiliatewp.com
 * Description: Sends an email to the affiliate when a referral has been paid
 * Author: Andrew Munro
 * Author URI: http://affiliatewp.com
 * Version: 1.0
 */
function affwp_eawrp_affiliate_referral_paid_email($referral_id, $new_status, $old_status)
{
    if (!function_exists('affiliate_wp') || ('paid' != $new_status || 'unpaid' != $old_status)) {
        return;
    }
    $referral = affiliate_wp()->referrals->get_by('referral_id', $referral_id);
    $affiliate_id = $referral->affiliate_id;
    $affiliate_email = affwp_get_affiliate_email($affiliate_id);
    $amount = html_entity_decode(affwp_currency_filter($referral->amount), ENT_COMPAT, 'UTF-8');
    $date = date_i18n(get_option('date_format'), strtotime($referral->date));
    // email subject
    $subject = sprintf('Congratulations, your referral for %s has just been paid', $amount);
    // email body
    $message = affwp_eawrp_affiliate_referral_paid_email_body($affiliate_id, $amount, $date);
    // send mail
    affiliate_wp()->emails->send($affiliate_email, $subject, $message);
}
Ejemplo n.º 5
0
 /**
  * Store a pending referral when a new order is created
  *
  * @access  public
  * @since   1.6
  */
 public function add_pending_referral($order_id, $cart, $order_totals, $user, $payment_type)
 {
     if ($this->was_referred()) {
         if (affwp_get_affiliate_email($this->affiliate_id) == $user->email) {
             return false;
             // Customers cannot refer themselves
         }
         if (affiliate_wp()->referrals->get_by('reference', $order_id, $this->context)) {
             return false;
             // Referral already created for this reference
         }
         $cart_shipping = $order_totals->shipping_total;
         $cart_tax = $order_totals->tax_total;
         $items = $cart->cart;
         // Calculate the referral amount based on product prices
         $amount = 0.0;
         foreach ($items as $cart_item) {
             if ($cart_item->has_affiliate_rule) {
                 continue;
                 // Referrals are disabled on this product
             }
             // The order discount has to be divided across the items
             $product_total = $cart_item->total_price;
             $shipping = 0;
             if ($cart_shipping > 0 && !affiliate_wp()->settings->get('exclude_shipping')) {
                 $shipping = $cart_shipping / count($items);
                 $product_total += $shipping;
             }
             if ($cart_tax > 0 && !affiliate_wp()->settings->get('exclude_tax')) {
                 $tax = $cart_tax / count($items);
                 $product_total += $tax;
             }
             if ($product_total <= 0) {
                 continue;
             }
             $amount += $this->calculate_referral_amount($product_total, $order_id, $cart_item->product_id);
         }
         if (0 == $amount && affiliate_wp()->settings->get('ignore_zero_referrals')) {
             return false;
             // Ignore a zero amount referral
         }
         $description = $this->get_referral_description($cart->cart);
         $visit_id = affiliate_wp()->tracking->get_visit_id();
         $referral_id = affiliate_wp()->referrals->add(apply_filters('affwp_insert_pending_referral', array('amount' => $amount, 'reference' => $order_id, 'description' => $description, 'affiliate_id' => $this->affiliate_id, 'visit_id' => $visit_id, 'context' => $this->context), $amount, $order_id, $description, $this->affiliate_id, $visit_id, array(), $this->context));
     }
 }
/**
 * Email the affiliate
 * Referrals must be "paid" before they will count towards the total referral count
 */
function affwp_referral_progress_emails($referral_id, $new_status, $old_status)
{
    // only count paid referrals
    if (!function_exists('affiliate_wp') || 'paid' != $new_status) {
        return;
    }
    // set up referral count goals
    // this would send an email on the 5th, 10th, 20th and 50th paid referral
    $referral_goals = array(5, 10, 20, 50);
    // get referral
    $referral = affwp_get_referral($referral_id);
    // get affiliate ID
    $affiliate_id = $referral->affiliate_id;
    // get the referral count for the affiliate
    $referral_count = affiliate_wp()->affiliates->get_column('referrals', $affiliate_id);
    // only send email if referral goal has been reached
    if (!in_array($referral_count, $referral_goals)) {
        return;
    }
    // return if no affiliate ID or no referral
    if (empty($affiliate_id) || empty($referral)) {
        return;
    }
    // set up email
    $emails = new Affiliate_WP_Emails();
    $emails->__set('affiliate_id', $affiliate_id);
    $emails->__set('referral', $referral);
    // get the affiliate's email address
    $email = affwp_get_affiliate_email($affiliate_id);
    // get affiliate's name
    $name = affiliate_wp()->affiliates->get_affiliate_name($affiliate_id);
    // set the email subject
    $subject = sprintf(__('Woohoo! You have reached %s referrals!', 'affiliate-wp'), $referral_count);
    // set the message
    $message = sprintf(__('Congratulations %s!', 'affiliate-wp'), $name) . "\n\n";
    $message .= sprintf(__('You\'ve reached a total of %s paid referrals! Keep going, you\'re doing great!', 'affiliate-wp'), $referral_count) . "\n\n";
    $message .= sprintf(__('Log in to your affiliate area to check your progress: %s', 'affiliate-wp'), affiliate_wp()->login->get_login_url()) . "\n\n";
    // send the email
    $emails->send($email, $subject, $message);
}
/**
 * Plugin Name: AffiliateWP - Custom Admin Registration Email
 * Plugin URI: http://affiliatewp.com
 * Description: Adds the Affiliate's Email and Affiliate ID to the admin registration email
 * Author: Andrew Munro
 * Author URI: http://affiliatewp.com
 * Version: 1.0
 */
function affwp_custom_registration_email($message, $args)
{
    $user_info = get_userdata(affwp_get_affiliate_user_id($args['affiliate_id']));
    $user_url = $user_info->user_url;
    $promotion_method = get_user_meta(affwp_get_affiliate_user_id($args['affiliate_id']), 'affwp_promotion_method', true);
    $message = "A new affiliate has registered on your site, " . home_url() . "\n\n";
    $message .= sprintf(__('Name: %s', 'affiliate-wp'), $args['name']) . "\n\n";
    // Affiliate's Email Address
    $message .= sprintf(__('Email: %s', 'affiliate-wp'), affwp_get_affiliate_email($args['affiliate_id'])) . "\n\n";
    // Affiliate's ID
    $message .= sprintf(__('Affiliate ID: %s', 'affiliate-wp'), $args['affiliate_id']) . "\n\n";
    if ($user_url) {
        $message .= __('Website URL: ', 'affiliate-wp') . esc_url($user_url) . "\n\n";
    }
    if ($promotion_method) {
        $message .= __('Promotion method: ', 'affiliate-wp') . esc_attr($promotion_method) . "\n\n";
    }
    if (affiliate_wp()->settings->get('require_approval')) {
        $message .= sprintf("Review pending applications: %s\n\n", admin_url('admin.php?page=affiliate-wp-affiliates&status=pending'));
    }
    return $message;
}
Ejemplo n.º 8
0
<?php

$affiliate_id = affwp_get_affiliate_id();
$user_email = affwp_get_affiliate_email($affiliate_id);
$payment_email = affwp_get_affiliate_payment_email($affiliate_id, $user_email);
// Fallback to user_email
?>

<div id="affwp-affiliate-dashboard-profile" class="affwp-tab-content">

	<h4><?php 
_e('Profile Settings', 'affiliate-wp');
?>
</h4>

	<form id="affwp-affiliate-dashboard-profile-form" class="affwp-form" method="post">

		<div class="affwp-wrap affwp-payment-email-wrap">
			<label for="affwp-payment-email"><?php 
_e('Your payment email', 'affiliate-wp');
?>
</label>
			<input id="affwp-payment-email" type="email" name="payment_email" value="<?php 
echo esc_attr($payment_email);
?>
" />
		</div>

		<div class="affwp-wrap affwp-send-notifications-wrap">
			<input id="affwp-referral-notifications" type="checkbox" name="referral_notifications" value="1" <?php 
checked(true, get_user_meta(affwp_get_affiliate_user_id($affiliate_id), 'affwp_referral_notifications', true));
Ejemplo n.º 9
0
/**
 * Send email on new referrals
 *
 * @since 1.6
 * @param int $affiliate_id The ID of the registered affiliate
 * @param array $referral
 */
function affwp_notify_on_new_referral($affiliate_id = 0, $referral)
{
    $user_id = affwp_get_affiliate_user_id($affiliate_id);
    if (!get_user_meta($user_id, 'affwp_referral_notifications', true)) {
        return;
    }
    if (empty($affiliate_id)) {
        return;
    }
    if (empty($referral)) {
        return;
    }
    $emails = new Affiliate_WP_Emails();
    $emails->__set('affiliate_id', $affiliate_id);
    $emails->__set('referral', $referral);
    $email = affwp_get_affiliate_email($affiliate_id);
    $subject = affiliate_wp()->settings->get('referral_subject', __('Referral Awarded!', 'affiliate-wp'));
    $message = affiliate_wp()->settings->get('referral_email', false);
    $amount = html_entity_decode(affwp_currency_filter($referral->amount), ENT_COMPAT, 'UTF-8');
    if (!$message) {
        $message = sprintf(__('Congratulations %s!', 'affiliate-wp'), affiliate_wp()->affiliates->get_affiliate_name($affiliate_id)) . "\n\n";
        $message .= sprintf(__('You have been awarded a new referral of %s on %s!', 'affiliate-wp'), $amount, home_url()) . "\n\n";
        $message .= sprintf(__('log into your affiliate area to view your earnings or disable these notifications: %s', 'affiliate-wp'), affiliate_wp()->login->get_login_url()) . "\n\n";
    }
    // $args is setup for backwards compatibility with < 1.6
    $args = array('affiliate_id' => $affiliate_id, 'amount' => $referral->amount, 'referral' => $referral);
    $subject = apply_filters('affwp_new_referral_subject', $subject, $args);
    $message = apply_filters('affwp_new_referral_email', $message, $args);
    if (apply_filters('affwp_notify_on_new_referral', true, $referral)) {
        $emails->send($email, $subject, $message);
    }
}
Ejemplo n.º 10
0
<div id="affwp-affiliate-dashboard-profile" class="affwp-tab-content p20 bg-white">

	<h4><?php 
_e('Profile Settings', 'affiliate-wp');
?>
</h4>

	<form id="affwp-affiliate-dashboard-profile-form" class="affwp-form" method="post">
		<div class="affwp-wrap affwp-payment-email-wrap">
			<label for="affwp-payment-email"><?php 
_e('Your payment email', 'affiliate-wp');
?>
</label>
			<input id="affwp-payment-email" class="w-50" type="email" name="payment_email" value="<?php 
echo esc_attr(affwp_get_affiliate_email(affwp_get_affiliate_id()));
?>
" />
		</div>

		<div class="affwp-wrap affwp-send-notifications-wrap">
			<input id="affwp-referral-notifications" type="checkbox" name="referral_notifications" value="1"<?php 
checked(true, get_user_meta(affwp_get_affiliate_user_id(affwp_get_affiliate_id()), 'affwp_referral_notifications', true));
?>
/>
			<label for="affwp-referral-notifications"><?php 
_e('Enable New Referral Notifications', 'affiliate-wp');
?>
</label>
		</div>

		<?php 
Ejemplo n.º 11
0
 function test_get_affiliate_email()
 {
     $this->assertEquals('*****@*****.**', affwp_get_affiliate_email($this->_affiliate_id));
     $args = array('affiliate_id' => $this->_affiliate_id, 'payment_email' => '*****@*****.**');
     affwp_update_affiliate($args);
     $this->assertEquals('*****@*****.**', affwp_get_affiliate_email($this->_affiliate_id));
 }
Ejemplo n.º 12
0
 /**
  * Determine if the passed email belongs to the affiliate
  *
  * Checks a given email address against the referring affiliate's
  * user email and payment email addresses to prevent customers from
  * referring themselves.
  *
  * @access  public
  * @since   1.6
  * @param   string $email
  * @return  bool
  */
 public function is_affiliate_email($email)
 {
     $is_affiliate_email = false;
     // Get affiliate emails
     $user_email = affwp_get_affiliate_email($this->affiliate_id);
     $payment_email = affwp_get_affiliate_payment_email($this->affiliate_id);
     // True if the email is valid and matches affiliate user email or payment email, otherwise false
     $is_affiliate_email = is_email($email) && ($user_email === $email || $payment_email === $email);
     return (bool) apply_filters('affwp_is_customer_email_affiliate_email', $is_affiliate_email, $email, $this->affiliate_id);
 }
Ejemplo n.º 13
0
 /**
  * Determine if the passed email belongs to the affiliate
  *
  * Checks a given email address against the referring affiliate's
  * user email and payment email addresses to prevent customers from
  * referring themselves.
  *
  * @access  public
  * @since   1.6
  * @param   string $email
  * @return  bool
  */
 public function is_affiliate_email($email, $affiliate_id = 0)
 {
     $is_affiliate_email = false;
     // allow an affiliate ID to be passed in
     $affiliate_id = isset($affiliate_id) ? $affiliate_id : $this->get_affiliate_id();
     // Get affiliate emails
     $user_email = affwp_get_affiliate_email($affiliate_id);
     $payment_email = affwp_get_affiliate_payment_email($affiliate_id);
     // True if the email is valid and matches affiliate user email or payment email, otherwise false
     $is_affiliate_email = is_email($email) && ($user_email === $email || $payment_email === $email);
     return (bool) apply_filters('affwp_is_customer_email_affiliate_email', $is_affiliate_email, $email, $affiliate_id);
 }
 /**
  * Get the affiliate's gravatar
  *
  * @since 1.0.0
  */
 public function get_affiliate_gravatar()
 {
     $affiliate_id = $this->get_affiliate_id();
     if ($affiliate_id) {
         $args = apply_filters('affwp_affiliate_info_gravatar_defaults', array('size' => 96, 'default' => '', 'alt' => $this->get_affiliate_name()));
         $email = affwp_get_affiliate_email($affiliate_id);
         return get_avatar(affwp_get_affiliate_user_id($affiliate_id), $args['size'], $args['default'], $args['alt']);
     }
     return false;
 }
Ejemplo n.º 15
0
 /**
  * Retrieves the email address of the referring affiliate
  *
  * @access  public
  * @since   1.0
  * @return  string
  */
 public function get_affiliate_email()
 {
     return affwp_get_affiliate_email($this->get_affiliate_id());
 }
/**
 * Retrieves the affiliate's payment email address
 *
 * @since  1.7
 * @param  object|int $affiliate
 * @return mixed
 */
function affwp_get_affiliate_payment_email($affiliate)
{
    $affiliate = is_numeric($affiliate) ? affwp_get_affiliate($affiliate) : $affiliate;
    if (empty($affiliate->payment_email) || !is_email($affiliate->payment_email)) {
        return affwp_get_affiliate_email($affiliate);
    }
    return $affiliate->payment_email;
}
Ejemplo n.º 17
0
/**
 * Email template tag: user_email
 * The affiliate's email
 *
 * @param int $affiliate_id
 * @return string email
 */
function affwp_email_tag_user_email($affiliate_id = 0)
{
    return affwp_get_affiliate_email($affiliate_id);
}
Ejemplo n.º 18
0
 function test_get_affiliate_email()
 {
     $args = array('affiliate_id' => $this->_affiliate_id, 'account_email' => '*****@*****.**');
     affwp_update_affiliate($args);
     $this->assertEquals('*****@*****.**', affwp_get_affiliate_email($this->_affiliate_id));
 }