/**
 * 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);
}
예제 #2
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);
    }
}