/**
 * Send referral email to admin
 * Requires AffiliateWP v1.6+
 */
function affwp_custom_referral_sale_email($add)
{
    $emails = new Affiliate_WP_Emails();
    $referral = affwp_get_referral($add);
    $affiliate_id = $referral->affiliate_id;
    $context = $referral->context;
    $reference = $referral->reference;
    $products = $referral->products;
    switch ($context) {
        case 'edd':
            $link = esc_url(admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $reference));
            break;
        case 'woocommerce':
            $link = esc_url(admin_url('post.php?post=' . $reference . '&action=edit'));
            break;
        default:
            $link = '';
            break;
    }
    $email = apply_filters('affwp_registration_admin_email', get_option('admin_email'));
    $amount = html_entity_decode(affwp_currency_filter($referral->amount), ENT_COMPAT, 'UTF-8');
    $subject = __('New referral sale!', 'affiliate-wp');
    $message = __('Congratulations!', 'affiliate-wp') . "\n\n";
    $message .= __('You have just received a new referral sale:', 'affiliate-wp') . "\n\n";
    if ($link) {
        $message .= sprintf(__('Order: %s ', 'affiliate-wp'), '<a href="' . $link . '">#' . $reference . '</a>') . "\n";
    } else {
        $message .= sprintf(__('Order: #%s ', 'affiliate-wp'), $reference) . "\n";
    }
    $message .= sprintf(__('Affiliate Name: %s ', 'affiliate-wp'), affiliate_wp()->affiliates->get_affiliate_name($affiliate_id)) . "\n";
    $message .= sprintf(__('Referral amount: %s ', 'affiliate-wp'), $amount) . "\n\n";
    $message .= __('Products that earned commission:', 'affiliate-wp') . "\n\n";
    if ($products) {
        foreach ($products as $product) {
            $referral_amount = html_entity_decode(affwp_currency_filter(affwp_format_amount($product['referral_amount'])), ENT_COMPAT, 'UTF-8');
            $message .= '<strong>' . $product['name'] . '</strong>' . "\n";
            $message .= sprintf(__('Referral Amount: %s ', 'affiliate-wp'), $referral_amount) . "\n\n";
        }
    }
    $emails->send($email, $subject, $message);
}
/**
 * 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);
}
 /**
  * Referral Payout
  * @since 1.6
  * @version 1.0
  */
 public function referral_payouts($referral_id, $new_status, $old_status)
 {
     // If the referral id isn't valid
     if (!is_numeric($referral_id)) {
         return;
     }
     // Get the referral object
     $referral = affwp_get_referral($referral_id);
     // Get the user id
     $user_id = affwp_get_affiliate_user_id($referral->affiliate_id);
     if (array_key_exists($currency, $this->point_types) && $this->prefs['referrals']['pay'] == 'store') {
         $amount = $referral->amount;
     } elseif ($this->prefs['referrals']['pay'] == 'amount') {
         $amount = $this->prefs['referrals']['creds'];
     } else {
         $amount = $this->core->number($referral->amount / $this->prefs['referrals']['creds']);
     }
     $amount = apply_filters('mycred_affiliatewp_payout', $amount, $referral, $new_status, $old_status, $this);
     if ('paid' === $new_status) {
         $this->core->add_creds('affiliate_referral', $user_id, $amount, $this->prefs['referrals']['log'], $referral_id, array('ref_type' => 'post'), $this->mycred_type);
     } elseif ('paid' === $old_status && 'unpaid' === $new_status) {
         $this->core->add_creds('affiliate_referral_refund', $user_id, 0 - $amount, $this->prefs['referrals']['remove_log'], $referral_id, array('ref_type' => 'post'), $this->mycred_type);
     }
 }
function affwp_delete_referral($referral)
{
    if (is_object($referral) && isset($referral->referral_id)) {
        $referral_id = $referral->referral_id;
    } elseif (is_numeric($referral)) {
        $referral_id = absint($referral);
        $referral = affwp_get_referral($referral_id);
    } else {
        return false;
    }
    if ($referral && 'paid' == $referral->status) {
        // This referral has already been paid, so decrease the affiliate's earnings
        affwp_decrease_affiliate_earnings($referral->affiliate_id, $referral->amount);
        // Decrease the referral count
        affwp_decrease_affiliate_referral_count($referral->affiliate_id);
    }
    if (affiliate_wp()->referrals->delete($referral_id)) {
        do_action('affwp_delete_referral', $referral_id);
        return true;
    }
    return false;
}
 function test_get_referral()
 {
     $this->assertNull(affwp_get_referral(0));
     $this->assertNotEmpty(affwp_get_referral($this->_referral_id));
 }
Exemple #6
0
<?php

$referral = affwp_get_referral(absint($_GET['referral_id']));
?>
<div class="wrap">

	<h2><?php 
_e('Edit Referral', 'affiliate-wp');
?>
</h2>

	<form method="post" id="affwp_edit_referral">

		<?php 
do_action('affwp_edit_referral_top', $referral);
?>

		<table class="form-table">


			<tr class="form-row form-required">

				<th scope="row">
					<label for="affiliate_id"><?php 
_e('Affiliate ID', 'affiliate-wp');
?>
</label>
				</th>

				<td>
					<input class="small-text" type="text" name="affiliate_id" id="affiliate_id" value="<?php