/** * 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); }
/** * 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); } }