Esempio n. 1
0
 /**
  * Trigger the tickets email
  *
  * @param int $payment_id
  *
  * @return string
  */
 public function trigger($payment_id = 0)
 {
     global $edd_options;
     $payment_data = edd_get_payment_meta($payment_id);
     $user_id = edd_get_payment_user_id($payment_id);
     $user_info = maybe_unserialize($payment_data['user_info']);
     $email = edd_get_payment_user_email($payment_id);
     if (isset($user_id) && $user_id > 0) {
         $user_data = get_userdata($user_id);
         $name = $user_data->display_name;
     } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
         $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
     } else {
         $name = $email;
     }
     $message = $this->get_content_html($payment_id);
     $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
     $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
     $subject = !empty($edd_options['ticket_subject']) ? wp_strip_all_tags($edd_options['ticket_subject'], true) : $this->default_subject;
     $subject = apply_filters('edd_ticket_receipt_subject', $subject, $payment_id);
     $subject = edd_email_template_tags($subject, $payment_data, $payment_id);
     $headers = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
     $headers .= 'Reply-To: ' . $from_email . "\r\n";
     $headers .= "Content-Type: text/html; charset=utf-8\r\n";
     $headers = apply_filters('edd_ticket_receipt_headers', $headers, $payment_id, $payment_data);
     // Allow add-ons to add file attachments
     $attachments = apply_filters('edd_ticket_receipt_attachments', array(), $payment_id, $payment_data);
     if (apply_filters('edd_email_ticket_receipt', true)) {
         wp_mail($email, $subject, $message, $headers, $attachments);
     }
 }
/**
 * Email the download link(s) and payment confirmation to the buyer in a
 * customizable Purchase Receipt
 *
 * @since 1.0
 * @param int $payment_id Payment ID
 * @param bool $admin_notice Whether to send the admin email notification or not (default: true)
 * @return void
 */
function edd_email_purchase_receipt($payment_id, $admin_notice = true)
{
    global $edd_options;
    $payment_data = edd_get_payment_meta($payment_id);
    $user_info = maybe_unserialize($payment_data['user_info']);
    $email = edd_get_payment_user_email($payment_id);
    if (isset($user_info['id']) && $user_info['id'] > 0) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_data->display_name;
    } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
        $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
    } else {
        $name = $email;
    }
    $message = edd_get_email_body_header();
    $message .= edd_get_email_body_content($payment_id, $payment_data);
    $message .= edd_get_email_body_footer();
    $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
    $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
    $subject = apply_filters('edd_purchase_subject', isset($edd_options['purchase_subject']) ? trim($edd_options['purchase_subject']) : __('Purchase Receipt', 'edd'), $payment_id);
    $subject = edd_email_template_tags($subject, $payment_data, $payment_id);
    $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
    $headers .= "Reply-To: " . $from_email . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    $headers = apply_filters('edd_receipt_headers', $headers, $payment_id, $payment_data);
    // Allow add-ons to add file attachments
    $attachments = apply_filters('edd_receipt_attachments', array(), $payment_id, $payment_data);
    wp_mail($email, $subject, $message, $headers, $attachments);
    if ($admin_notice && !edd_admin_notices_disabled()) {
        do_action('edd_admin_sale_notice', $payment_id, $payment_data);
    }
}
/**
 * Email Download Purchase Receipt
 *
 * Email the download link(s) and payment confirmation to the buyer.
 *
 * @access      private
 * @since       1.0
 * @return      void
*/
function edd_email_purchase_receipt($payment_id, $admin_notice = true)
{
    global $edd_options;
    $payment_data = edd_get_payment_meta($payment_id);
    $user_info = maybe_unserialize($payment_data['user_info']);
    if (isset($user_info['id']) && $user_info['id'] > 0) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_data->display_name;
    } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
        $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
    } else {
        $name = $user_info['email'];
    }
    $message = edd_get_email_body_header();
    $message .= edd_get_email_body_content($payment_id, $payment_data);
    $message .= edd_get_email_body_footer();
    $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
    $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
    $subject = isset($edd_options['purchase_subject']) && strlen(trim($edd_options['purchase_subject'])) > 0 ? edd_email_template_tags($edd_options['purchase_subject'], $payment_data, $payment_id) : __('Purchase Receipt', 'edd');
    $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
    $headers .= "Reply-To: " . $from_email . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    // allow add-ons to add file attachments
    $attachments = apply_filters('edd_receipt_attachments', array(), $payment_id, $payment_data);
    wp_mail($payment_data['email'], $subject, $message, $headers, $attachments);
    if ($admin_notice) {
        /* send an email notification to the admin */
        $admin_email = edd_get_admin_notice_emails();
        $admin_subject = apply_filters('edd_admin_purchase_notification_subject', __('New download purchase', 'edd'), $payment_id, $payment_data);
        $admin_message = __('Hello', 'edd') . "\n\n" . sprintf(__('A %s purchase has been made', 'edd'), edd_get_label_plural()) . ".\n\n";
        $admin_message .= sprintf(__('%s sold:', 'edd'), edd_get_label_plural()) . "\n\n";
        $download_list = '';
        $downloads = maybe_unserialize($payment_data['downloads']);
        if (is_array($downloads)) {
            foreach ($downloads as $download) {
                $id = isset($payment_data['cart_details']) ? $download['id'] : $download;
                $download_list .= html_entity_decode(get_the_title($id), ENT_COMPAT, 'UTF-8') . "\n";
            }
        }
        $gateway = edd_get_gateway_admin_label(get_post_meta($payment_id, '_edd_payment_gateway', true));
        $admin_message .= $download_list . "\n";
        $admin_message .= __('Purchased by: ', 'edd') . " " . html_entity_decode($name, ENT_COMPAT, 'UTF-8') . "\n";
        $admin_message .= __('Amount: ', 'edd') . " " . html_entity_decode(edd_currency_filter(edd_format_amount($payment_data['amount'])), ENT_COMPAT, 'UTF-8') . "\n\n";
        $admin_message .= __('Payment Method: ', 'edd') . " " . $gateway . "\n\n";
        $admin_message .= __('Thank you', 'edd');
        $admin_message = apply_filters('edd_admin_purchase_notification', $admin_message, $payment_id, $payment_data);
        $admin_headers = apply_filters('edd_admin_purchase_notification_headers', array(), $payment_id, $payment_data);
        $admin_attachments = apply_filters('edd_admin_purchase_notification_attachments', array(), $payment_id, $payment_data);
        wp_mail($admin_email, $admin_subject, $admin_message, $admin_headers, $admin_attachments);
    }
}
/**
 * Email Template Body
 *
 * @since 1.0.8.2
 * @param int $payment_id Payment ID
 * @param array $payment_data Payment Data
 * @return string $email_body Body of the email
 */
function edd_get_email_body_content($payment_id = 0, $payment_data = array())
{
    global $edd_options;
    $default_email_body = __("Dear", "edd") . " {name},\n\n";
    $default_email_body .= __("Thank you for your purchase. Please click on the link(s) below to download your files.", "edd") . "\n\n";
    $default_email_body .= "{download_list}\n\n";
    $default_email_body .= "{sitename}";
    $email = isset($edd_options['purchase_receipt']) ? $edd_options['purchase_receipt'] : $default_email_body;
    $email_body = edd_email_template_tags($email, $payment_data, $payment_id);
    return apply_filters('edd_purchase_receipt', $email_body, $payment_id, $payment_data);
}
Esempio n. 5
0
/**
 * Email the product update to the customer in a customizable message
 *
 * @param int $payment_id Payment ID
 * @param int $email_id Email ID for a edd_pup_email post-type
 * @return void
 */
function edd_pup_ajax_send_email($payment_id, $email_id, $test_mode = null)
{
    $userid = get_current_user_id();
    $emailpost = get_post($email_id);
    $emailmeta = get_post_custom($email_id);
    $payment_data = edd_get_payment_meta($payment_id);
    $email = edd_get_payment_user_email($payment_id);
    $from_name = $emailmeta['_edd_pup_from_name'][0];
    $from_email = $emailmeta['_edd_pup_from_email'][0];
    $attachments = apply_filters('edd_pup_attachments', array(), $payment_id, $payment_data);
    $lognotes = edd_get_option('edd_pup_log_notes');
    add_filter('edd_email_template', 'edd_pup_template');
    /* If subject doesn't use tags (and thus is the same for each customer)
     * then store it in a transient for quick access on subsequent loops. */
    $subject = get_transient('edd_pup_subject_' . $userid);
    if (false === $subject || $emailmeta['_edd_pup_subject'][0] != $subject) {
        if (empty($emailmeta['_edd_pup_subject'][0])) {
            $subject = '(no subject)';
            wp_update_post(array('ID' => $email_id, 'post_excerpt' => $subject));
            update_post_meta($email_id, '_edd_pup_subject', $subject);
            set_transient('edd_pup_subject_' . $userid, $subject, 60 * 60);
        } else {
            $subject = edd_do_email_tags($emailmeta['_edd_pup_subject'][0], $payment_id);
            if ($subject == $emailmeta['_edd_pup_subject'][0]) {
                set_transient('edd_pup_subject_' . $userid, $subject, 60 * 60);
            }
        }
    }
    if (version_compare(get_option('edd_version'), '2.1') >= 0) {
        $edd_emails = new EDD_emails();
        $message = edd_do_email_tags($emailpost->post_content, $payment_id);
        $edd_emails->__set('from_name', $from_name);
        $edd_emails->__set('from_address', $from_email);
        $mailresult = isset($test_mode) ? true : $edd_emails->send($email, $subject, $message, $attachments);
    } else {
        $email_body_header = get_transient('edd_pup_email_body_header_' . $userid);
        if (false === $email_body_header) {
            $email_body_header = edd_get_email_body_header();
            set_transient('edd_pup_email_body_header_' . $userid, $email_body_header, 60 * 60);
        }
        $email_body_footer = get_transient('edd_pup_email_body_footer_' . $userid);
        if (false === $email_body_footer) {
            $email_body_footer = edd_get_email_body_footer();
            set_transient('edd_pup_email_body_footer_' . $userid, $email_body_footer, 60 * 60);
        }
        $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
        $headers .= "Reply-To: " . $from_email . "\r\n";
        $headers .= "Content-Type: text/html; charset=utf-8\r\n";
        $message = $email_body_header;
        $message .= apply_filters('edd_pup_message', edd_email_template_tags($emailpost->post_content, $payment_data, $payment_id), $payment_id, $payment_data);
        $message .= $email_body_footer;
        $mailresult = isset($test_mode) ? true : wp_mail($email, $subject, $message, $headers, $attachments);
    }
    // Update payment notes to log this email being sent
    if (!isset($lognotes['sent'])) {
        edd_insert_payment_note($payment_id, 'Sent product update email "' . $subject . '" <a href="' . admin_url('edit.php?post_type=download&page=edd-prod-updates&view=view_pup_email&id=' . $email_id) . '">View Email</a>');
    }
    return $mailresult;
}
/**
 * Email the custom download link(s) and payment confirmation to the buyer in a
 * customizable Purchase Receipt
 *
 * @since 1.0
 * @param int $payment_id Payment ID
 * @param bool $admin_notice Whether to send the admin email notification or not (default: true)
 * @return void
 */
function edd_ppe_email_custom_purchase_receipts($payment_id, $admin_notice = true)
{
    $payment_data = edd_get_payment_meta($payment_id);
    $user_id = edd_get_payment_user_id($payment_id);
    $user_info = maybe_unserialize($payment_data['user_info']);
    $email = edd_get_payment_user_email($payment_id);
    if (isset($user_id) && $user_id > 0) {
        $user_data = get_userdata($user_id);
        $name = $user_data->display_name;
    } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
        $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
    } else {
        $name = $email;
    }
    // get cart items from payment ID
    $cart_items = edd_get_payment_meta_cart_details($payment_id);
    // loop through each item in cart and add IDs to $product_id array
    foreach ($cart_items as $product) {
        $product_ids[] = $product['id'];
    }
    foreach ($product_ids as $product_id) {
        if (!edd_ppe_is_receipt_active(edd_ppe_get_receipt_id($product_id))) {
            continue;
        }
        $receipt = get_post(edd_ppe_get_receipt_id($product_id));
        // default email body
        $default_email_body = __("Dear", "edd-ppe") . " {name},\n\n";
        $default_email_body .= __("Thank you for purchasing {download_name}. Please click on the link(s) below to download your files.", "edd-ppe") . "\n\n";
        $default_email_body .= "{download_list}\n\n";
        $default_email_body .= "{sitename}";
        // use new EDD 2.1 Email class
        if (class_exists('EDD_Emails')) {
            // get our subject
            $subject = apply_filters('edd_ppe_purchase_subject', $receipt->post_excerpt ? wp_strip_all_tags($receipt->post_excerpt, true) : __('Purchase Receipt - {download_name}', 'edd-ppe'), $payment_id);
            // run subject through the plugin's custom email tag function
            // this runs before so apostrophe's can correctly be replaced when {sitename} is used in the subject. This will eventually be fixed in EDD core
            $subject = edd_ppe_email_template_tags($subject, $product_id);
            // run subject through the standard EDD email tag function
            $subject = edd_do_email_tags($subject, $payment_id);
            // message
            $message = apply_filters('edd_ppe_purchase_body', $receipt->post_content ? $receipt->post_content : $default_email_body);
            // run our message through the standard EDD email tag function
            $message = apply_filters('edd_purchase_receipt', edd_do_email_tags($message, $payment_id), $payment_id, $payment_data);
            // run the message through the plugin's custom email tag function
            $message = edd_ppe_email_template_tags($message, $product_id);
            // add download name as email heading. Off by default
            // will introduce a checkbox in admin to turn all headings on rather than turn them on now which may mess up emails
            if (apply_filters('edd_ppe_email_heading', false)) {
                EDD()->emails->__set('heading', get_the_title($product_id));
            }
            // send an email for each custom email
            EDD()->emails->send($email, $subject, $message);
        } else {
            // support older EDD versions where the EDD Email Class does not exist
            $subject = apply_filters('edd_ppe_purchase_subject', $receipt->post_excerpt ? wp_strip_all_tags($receipt->post_excerpt, true) : __('Purchase Receipt - {download_name}', 'edd-ppe'), $payment_id);
            $body = apply_filters('edd_ppe_purchase_body', $receipt->post_content ? $receipt->post_content : $default_email_body);
            $body = edd_ppe_email_template_tags($body, $product_id);
            $subject = edd_email_template_tags($subject, $payment_data, $payment_id);
            $subject = edd_ppe_email_template_tags($subject, $product_id);
            $message = edd_get_email_body_header();
            $message .= apply_filters('edd_purchase_receipt', edd_email_template_tags($body, $payment_data, $payment_id), $payment_id, $payment_data);
            $message .= edd_get_email_body_footer();
            $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
            $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
            $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
            $headers .= "Reply-To: " . $from_email . "\r\n";
            //$headers .= "MIME-Version: 1.0\r\n";
            $headers .= "Content-Type: text/html; charset=utf-8\r\n";
            $headers = apply_filters('edd_receipt_headers', $headers, $payment_id, $payment_data);
            // Allow add-ons to add file attachments
            $attachments = apply_filters('edd_receipt_attachments', array(), $payment_id, $payment_data);
            wp_mail($email, $subject, $message, $headers, $attachments);
        }
    }
}
/**
 * Build the campaign expired email.
 *
 * Figure out who to send to, who it's from, etc.
 *
 * @since Astoundify Crowdfunding 1.6
 *
 * @param object $campaign
 * @return void
 */
function atcf_email_campaign_expiration($campaign)
{
    global $edd_options;
    $message = edd_get_email_body_header();
    $default_email_body = __('Dear Author', 'atcf') . "\n\n";
    $default_email_body .= sprintf(__('We would just like to let you know that your campaign has reached its end date. You can view your campaign by clicking <a href="%s">here</a>.', 'atcf'), get_permalink($campaign->ID));
    $message .= apply_filters('atcf_campaign_expiration_message', $default_email_body, $campaign);
    $message .= edd_get_email_body_footer();
    $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
    $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
    $subject = apply_filters('atcf_campaign_expiration_subject', __('Your campaign is complete!', 'atcf'), $campaign);
    $subject = edd_email_template_tags($subject, $payment_data, $payment_id);
    $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
    $headers .= "Reply-To: " . $from_email . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    wp_mail($campaign->contact_email(), $subject, $message, $headers);
}