Exemplo n.º 1
0
 /**
  * Add pending referral
  *
  * @function add_pending_referral
  * @access public
  */
 public function add_pending_referral($order_id = 0)
 {
     if ($this->was_referred()) {
         $this->order = apply_filters('affwp_get_jigoshop_order', new jigoshop_order($order_id));
         // Fetch order
         if ($this->is_affiliate_email($this->order->billing_email)) {
             return;
             // Customers cannot refer themselves
         }
         $description = '';
         $items = $this->order->items;
         foreach ($items as $key => $item) {
             $description .= $item['name'];
             if ($key + 1 < count($items)) {
                 $description .= ', ';
             }
         }
         $amount = $this->order->order_total;
         if (affiliate_wp()->settings->get('exclude_tax')) {
             $amount -= $this->order->get_total_tax();
         }
         if (affiliate_wp()->settings->get('exclude_shipping')) {
             $amount -= $this->order->order_shipping;
         }
         $referral_total = $this->calculate_referral_amount($amount, $order_id);
         $this->insert_pending_referral($referral_total, $order_id, $description);
         $referral = affiliate_wp()->referrals->get_by('reference', $order_id, $this->context);
         $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
         $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
         $this->order->add_order_note(sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral->referral_id, $amount, $name));
     }
 }
 /**
  * Revoke a referral when a payment is refunded
  *
  * @access  public
  * @since   1.6
  */
 public function revoke_referral_on_refund($payment_id = 0)
 {
     if (!affiliate_wp()->settings->get('revoke_on_refund')) {
         return;
     }
     $this->reject_referral($payment_id);
     $referral = affiliate_wp()->referrals->get_by('reference', $payment_id, $this->context);
     $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
     $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
     $note = sprintf(__('Referral #%d for %s for %s rejected', 'affiliate-wp'), $referral->referral_id, $amount, $name);
     $payment = SI_Payment::get_instance($payment_id);
     $new_data = wp_parse_args($payment->get_data(), array('affwp_notes' => $note));
     $payment->set_data($new_data);
 }
/**
 * 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);
}
Exemplo n.º 4
0
 public function mark_referral_complete($order)
 {
     if ('success' !== strtolower($order->status)) {
         return;
     }
     $this->complete_referral($order->id);
     $referral = affiliate_wp()->referrals->get_by('reference', $order->id, $this->context);
     $order = new MemberOrder($order->id);
     // Prevent infinite loop
     remove_action('pmpro_updated_order', array($this, 'mark_referral_complete'), 10);
     $order->affiliate_id = $referral->affiliate_id;
     $amount = html_entity_decode(affwp_currency_filter(affwp_format_amount($referral->amount)), ENT_QUOTES, 'UTF-8');
     $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
     $note = sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral->referral_id, $amount, $name);
     if (empty($order->notes)) {
         $order->notes = $note;
     } else {
         $order->notes = $order->notes . "\n\n" . $note;
     }
     $order->saveOrder();
 }
Exemplo n.º 5
0
 public function add_pending_referral($order_id = 0)
 {
     if ($this->was_referred()) {
         $this->order = apply_filters('affwp_get_shopp_order', shopp_order($order_id->order));
         $customer_email = $this->order->email;
         if ($this->is_affiliate_email($customer_email)) {
             return;
             // Customers cannot refer themselves
         }
         $description = '';
         foreach ($this->order->purchased as $key => $item) {
             $description .= $item->name;
             if ($key + 1 < count($this->order->purchased)) {
                 $description .= ', ';
             }
         }
         $amount = $this->order->total;
         if (affiliate_wp()->settings->get('exclude_tax')) {
             $amount -= $this->order->tax;
         }
         if (affiliate_wp()->settings->get('exclude_shipping')) {
             $amount -= $this->order->shipping;
         }
         $referral_total = $this->calculate_referral_amount($amount, $order_id->order);
         $this->insert_pending_referral($referral_total, $order_id->order, $description);
         $referral = affiliate_wp()->referrals->get_by('reference', $order_id->order, 'shopp');
         $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
         $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
         $user = wp_get_current_user();
         $Note = new ShoppMetaObject();
         $Note->parent = $order_id->order;
         $Note->context = 'purchase';
         $Note->type = 'order_note';
         $Note->value = new stdClass();
         $Note->value->author = $user->ID;
         $Note->value->message = sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral->referral_id, $amount, $name);
         $Note->save();
     }
 }
Exemplo n.º 6
0
 /**
  * Store a pending referral when a new order is created
  *
  * @access  public
  * @since   1.0
  */
 public function add_pending_referral($order_id = 0, $posted)
 {
     $this->order = apply_filters('affwp_get_woocommerce_order', new WC_Order($order_id));
     // Check if an affiliate coupon was used
     $coupon_affiliate_id = $this->get_coupon_affiliate_id();
     if ($this->was_referred() || $coupon_affiliate_id) {
         // get affiliate ID
         $affiliate_id = $this->get_affiliate_id($order_id);
         if (false !== $coupon_affiliate_id) {
             $affiliate_id = $coupon_affiliate_id;
         }
         // Customers cannot refer themselves
         if ($this->is_affiliate_email($this->order->billing_email, $affiliate_id)) {
             return false;
         }
         // Check for an existing referral
         $existing = affiliate_wp()->referrals->get_by('reference', $order_id, $this->context);
         // If an existing referral exists and it is paid or unpaid exit.
         if ($existing && ('paid' == $existing->status || 'unpaid' == $existing->status)) {
             return false;
             // Completed Referral already created for this reference
         }
         $cart_shipping = $this->order->get_total_shipping();
         $items = $this->order->get_items();
         // Calculate the referral amount based on product prices
         $amount = 0.0;
         foreach ($items as $product) {
             if (get_post_meta($product['product_id'], '_affwp_' . $this->context . '_referrals_disabled', true)) {
                 continue;
                 // Referrals are disabled on this product
             }
             // The order discount has to be divided across the items
             $product_total = $product['line_total'];
             $shipping = 0;
             if ($cart_shipping > 0 && !affiliate_wp()->settings->get('exclude_shipping')) {
                 $shipping = $cart_shipping / count($items);
                 $product_total += $shipping;
             }
             if (!affiliate_wp()->settings->get('exclude_tax')) {
                 $product_total += $product['line_tax'];
             }
             if ($product_total <= 0) {
                 continue;
             }
             $amount += $this->calculate_referral_amount($product_total, $order_id, $product['product_id'], $affiliate_id);
         }
         if (0 == $amount && affiliate_wp()->settings->get('ignore_zero_referrals')) {
             return false;
             // Ignore a zero amount referral
         }
         $description = $this->get_referral_description();
         $visit_id = affiliate_wp()->tracking->get_visit_id();
         if ($existing) {
             // Update the previously created referral
             affiliate_wp()->referrals->update_referral($existing->referral_id, array('amount' => $amount, 'reference' => $order_id, 'description' => $description, 'campaign' => affiliate_wp()->tracking->get_campaign(), 'affiliate_id' => $affiliate_id, 'visit_id' => $visit_id, 'products' => $this->get_products(), 'context' => $this->context));
         } else {
             // Create a new referral
             $referral_id = affiliate_wp()->referrals->add(apply_filters('affwp_insert_pending_referral', array('amount' => $amount, 'reference' => $order_id, 'description' => $description, 'campaign' => affiliate_wp()->tracking->get_campaign(), 'affiliate_id' => $affiliate_id, 'visit_id' => $visit_id, 'products' => $this->get_products(), 'context' => $this->context), $amount, $order_id, $description, $affiliate_id, $visit_id, array(), $this->context));
             if ($referral_id) {
                 $amount = affwp_currency_filter(affwp_format_amount($amount));
                 $name = affiliate_wp()->affiliates->get_affiliate_name($affiliate_id);
                 $this->order->add_order_note(sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral_id, $amount, $name));
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Revoke referral on refund
  *
  * @access public
  * @uses GFFormsModel::add_note()
  *
  * @param array $entry
  * @param array $action
  */
 public function revoke_referral_on_refund($entry, $action)
 {
     $this->reject_referral($entry['id']);
     $referral = affiliate_wp()->referrals->get_by('reference', $entry['id'], $this->context);
     $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
     $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
     $note = sprintf(__('Referral #%d for %s for %s rejected', 'affiliate-wp'), $referral->referral_id, $amount, $name);
     GFFormsModel::add_note($entry["id"], 0, 'AffiliateWP', $note);
 }
Exemplo n.º 8
0
 /**
  * Render the amount column
  *
  * @access public
  * @since 1.0
  * @param array $referral Contains all the data for the checkbox column
  * @return string Displays the referral amount
  */
 public function column_amount($referral)
 {
     return affwp_currency_filter(affwp_format_amount($referral->amount));
 }
do_action('affwp_referrals_dashboard_th');
?>
			</tr>
		</thead>

		<tbody>
			<?php 
if ($referrals) {
    ?>

				<?php 
    foreach ($referrals as $referral) {
        ?>
					<tr>
						<td class="referral-amount"><?php 
        echo affwp_currency_filter(affwp_format_amount($referral->amount));
        ?>
</td>
						<td class="referral-description"><?php 
        echo wp_kses_post(nl2br($referral->description));
        ?>
</td>
						<td class="referral-status <?php 
        echo $referral->status;
        ?>
"><?php 
        echo affwp_get_referral_status_label($referral);
        ?>
</td>
						<td class="referral-date"><?php 
        echo date_i18n(get_option('date_format'), strtotime($referral->date));
        ?>
</td>
						<td><?php 
        echo esc_html($campaign->visits);
        ?>
</td>
						<td><?php 
        echo esc_html($campaign->unique_visits);
        ?>
</td>
						<td><?php 
        echo esc_html($campaign->referrals);
        ?>
</td>
						<td><?php 
        echo esc_html(affwp_format_amount($campaign->conversion_rate));
        ?>
%</td>
					</tr>
				<?php 
    }
    ?>
			<?php 
} else {
    ?>
				<tr>
					<td colspan="5"><?php 
    _e('You have no referrals or visits that included a campaign name.', 'affiliate-wp');
    ?>
</td>
				</tr>
    /**
     * Get referrals
     *
     * @since  1.0
     * @return string
     */
    public function show_leaderboard($args = array())
    {
        $defaults = apply_filters('affwp_leaderboard_defaults', array('number' => isset($args['number']) ? $args['number'] : 10, 'orderby' => isset($args['orderby']) ? $args['orderby'] : 'referrals'));
        $args = wp_parse_args($args, $defaults);
        // show an affiliate's earnings
        $show_earnings = isset($args['earnings']) && ('yes' == $args['earnings'] || 'on' == $args['earnings']) ? true : false;
        // show an affiliate's referrals
        $show_referrals = isset($args['referrals']) && ('yes' == $args['referrals'] || 'on' == $args['referrals']) ? true : false;
        // show an affiliate's visits
        $show_visits = isset($args['visits']) && ('yes' == $args['visits'] || 'on' == $args['visits']) ? true : false;
        // get affiliates
        $affiliates = affiliate_wp()->affiliates->get_affiliates($defaults);
        ob_start();
        if ($affiliates) {
            ?>

		<ol class="affwp-leaderboard">
		<?php 
            foreach ($affiliates as $affiliate) {
                ?>
			<li><?php 
                // affiliate name
                echo affiliate_wp()->affiliates->get_affiliate_name($affiliate->affiliate_id);
                $to_show = apply_filters('affwp_leaderboard_to_show', array('referrals' => $show_referrals, 'earnings' => $show_earnings, 'visits' => $show_visits));
                $output = array();
                if ($to_show) {
                    foreach ($to_show as $key => $value) {
                        if ($value && $key == 'referrals') {
                            $output[] = absint($affiliate->referrals) . ' ' . __('referrals', 'affiliatewp-leaderboard');
                        }
                        if ($value && $key == 'earnings') {
                            $output[] = affwp_currency_filter(affwp_format_amount($affiliate->earnings)) . ' ' . __('earnings', 'affiliatewp-leaderboard');
                        }
                        if ($value && $key == 'visits') {
                            $output[] = absint($affiliate->visits) . ' ' . __('visits', 'affiliatewp-leaderboard');
                        }
                    }
                }
                $output = implode('&nbsp;&nbsp;<span class="divider">|</span>&nbsp;&nbsp;', $output);
                if ($output) {
                    echo '<p>' . $output . '</p>';
                }
                ?>
</li>
		<?php 
            }
            ?>
		</ol>
		<?php 
        } else {
            ?>
			<?php 
            _e('No registered affiliates', 'affiliatewp-leaderboard');
            ?>
		<?php 
        }
        ?>


		<?php 
        $html = ob_get_clean();
        return apply_filters('affwp_show_leaderboard', $html, $affiliates, $show_referrals, $show_earnings, $show_visits);
    }
Exemplo n.º 12
0
 /**
  * Get the total unpaid earnings
  *
  * @access  public
  * @since   1.0
  */
 public function unpaid_earnings($date = '', $affiliate_id = 0, $format = true)
 {
     $args = array();
     $args['status'] = 'unpaid';
     $args['affiliate_id'] = $affiliate_id;
     $args['number'] = '-1';
     if (!empty($date)) {
         switch ($date) {
             case 'month':
                 $date = array('start' => date('Y-m-01 00:00:00', current_time('timestamp')), 'end' => date('Y-m-' . cal_days_in_month(CAL_GREGORIAN, date('n'), date('Y')) . ' 00:00:00', current_time('timestamp')));
                 break;
         }
         $args['date'] = $date;
     }
     $referrals = $this->get_referrals($args);
     $earnings = array_sum(wp_list_pluck($referrals, 'amount'));
     if ($format) {
         $earnings = affwp_currency_filter(affwp_format_amount($earnings));
     }
     return $earnings;
 }
Exemplo n.º 13
0
 /**
  * Render the amount column
  *
  * @access public
  * @since 1.0
  * @param array $referral Contains all the data for the checkbox column
  * @return string Displays the referral amount
  */
 public function column_amount($referral)
 {
     $value = affwp_currency_filter(affwp_format_amount($referral->amount));
     return apply_filters('affwp_referral_table_amount', $value, $referral);
 }
Exemplo n.º 14
0
 /**
  * Mark referral as complete when payment is completed
  *
  * @access  public
  * @since   1.7
  */
 public function mark_referral_complete(Zippy_Event $event)
 {
     if ($event->new_status == 'complete' && $event->old_status != 'complete') {
         $order = $event->order;
         $referral = affiliate_wp()->referrals->get_by('reference', $order->getId(), $this->context);
         if (!$referral) {
             return;
         }
         $this->complete_referral($order->getId());
         $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
         $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
         $note = sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral->referral_id, $amount, $name);
         $order->addNote(array('content' => $note, 'timestamp' => time()));
         $order->saveNotes();
     }
 }
Exemplo n.º 15
0
 /**
  * Insert payment note
  *
  * @access  public
  * @since   1.3.1
  */
 public function insert_payment_note($payment_id = 0)
 {
     $referral = affiliate_wp()->referrals->get_by('reference', $payment_id, $this->context);
     if (empty($referral)) {
         return;
     }
     $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
     $affiliate_id = $referral->affiliate_id;
     $name = affiliate_wp()->affiliates->get_affiliate_name($affiliate_id);
     edd_insert_payment_note($payment_id, sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral->referral_id, $amount, $name));
 }
Exemplo n.º 16
0
 /**
  * Render the earnings column
  *
  * @access public
  * @since 1.0
  * @param array $affiliate Contains all the data for the earnings column
  * @return string earnings link
  */
 function column_earnings($affiliate)
 {
     $value = affwp_currency_filter(affwp_format_amount(affwp_get_affiliate_earnings($affiliate->affiliate_id)));
     return apply_filters('affwp_affiliate_table_earnings', $value, $affiliate);
 }
Exemplo n.º 17
0
 /**
  * Update referral status and add note to Formidable Pro entry
  *
  * @since 1.6
  *
  * @author Naomi C. Bush <*****@*****.**>
  *
  * @param int $entry_id
  * @param int $form_id
  */
 public function revoke_referral_on_refund($entry_id, $form_id)
 {
     global $frm_entry_meta;
     $this->reject_referral($entry_id);
     $referral = affiliate_wp()->referrals->get_by('reference', $entry_id, $this->context);
     $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
     $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
     $note = sprintf(__('AffiliateWP: Referral #%d for %s for %s rejected', 'affiliate-wp'), $referral->referral_id, $amount, $name);
     $frm_entry_meta->add_entry_meta($entry_id, 0, '', array('comment' => $note, 'user_id' => 0));
 }
Exemplo n.º 18
0
 /**
  * Render the earnings column
  *
  * @access public
  * @since 1.0
  * @param array $affiliate Contains all the data for the earnings column
  * @return string earnings link
  */
 function column_earnings($affiliate)
 {
     return affwp_currency_filter(affwp_format_amount(affwp_get_affiliate_earnings($affiliate->affiliate_id)));
 }
    /**
     * Show an affiliate's campaign stats
     *
     * [affiliate_campaign_stats]
     *
     * @since  1.1.1
     */
    function affiliate_campaign_stats($atts, $content = null)
    {
        if (!(affwp_is_affiliate() && affwp_is_active_affiliate())) {
            return;
        }
        ob_start();
        ?>

		<div id="affwp-affiliate-dashboard-campaign-stats" class="affwp-tab-content">
			<table class="affwp-table">
				<thead>
					<tr>
						<th><?php 
        _e('Campaign', 'affiliatewp-affiliate-area-shortcodes');
        ?>
</th>
						<th><?php 
        _e('Visits', 'affiliatewp-affiliate-area-shortcodes');
        ?>
</th>
						<th><?php 
        _e('Unique Links', 'affiliatewp-affiliate-area-shortcodes');
        ?>
</th>
						<th><?php 
        _e('Converted', 'affiliatewp-affiliate-area-shortcodes');
        ?>
</th>
						<th><?php 
        _e('Conversion Rate', 'affiliatewp-affiliate-area-shortcodes');
        ?>
</th>
					</tr>
				</thead>

				<tbody>
					<?php 
        if ($campaigns = affwp_get_affiliate_campaigns(affwp_get_affiliate_id())) {
            ?>
						<?php 
            foreach ($campaigns as $campaign) {
                ?>
							<tr>
								<td><?php 
                echo !empty($campaign->campaign) ? esc_html($campaign->campaign) : __('None set', 'affiliatewp-affiliate-area-shortcodes');
                ?>
</td>
								<td><?php 
                echo esc_html($campaign->visits);
                ?>
</td>
								<td><?php 
                echo esc_html($campaign->unique_visits);
                ?>
</td>
								<td><?php 
                echo esc_html($campaign->referrals);
                ?>
</td>
								<td><?php 
                echo esc_html(affwp_format_amount($campaign->conversion_rate));
                ?>
%</td>
							</tr>
						<?php 
            }
            ?>
					<?php 
        } else {
            ?>
						<tr>
							<td colspan="5"><?php 
            _e('You have no referrals or visits that included a campaign name.', 'affiliatewp-affiliate-area-shortcodes');
            ?>
</td>
						</tr>
					<?php 
        }
        ?>
				</tbody>
			</table>

			<?php 
        do_action('affwp_affiliate_dashboard_after_campaign_stats', affwp_get_affiliate_id());
        ?>

		</div>

		<?php 
        $content = ob_get_clean();
        return do_shortcode($content);
    }