Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • edd_admin_email_notice
  • edd_apply_email_template
  • edd_default_email_styling
  • edd_default_email_template
  • edd_email_default_formatting
  • edd_email_preview_templage_tags
  • edd_email_purchase_receipt
  • edd_email_template_preview
  • edd_email_template_tags
  • edd_email_test_purchase_receipt
  • edd_get_admin_notice_emails
  • edd_get_email_body_content
  • edd_get_email_body_footer
  • edd_get_email_body_header
  • edd_get_email_templates
  • edd_render_receipt_in_browser
  • edd_resend_purchase_receipt
  • edd_send_test_email
  • edd_trigger_purchase_receipt
  1 <?php
  2 /**
  3  * Email Functions
  4  *
  5  * @package     EDD
  6  * @subpackage  Emails
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.0
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 /**
 16  * Email the download link(s) and payment confirmation to the buyer in a
 17  * customizable Purchase Receipt
 18  *
 19  * @since 1.0
 20  * @param int $payment_id Payment ID
 21  * @param bool $admin_notice Whether to send the admin email notification or not (default: true)
 22  * @return void
 23  */
 24 function edd_email_purchase_receipt( $payment_id, $admin_notice = true ) {
 25     global $edd_options;
 26 
 27     $payment_data = edd_get_payment_meta( $payment_id );
 28     $user_info = maybe_unserialize( $payment_data['user_info'] );
 29 
 30     if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) {
 31         $user_data = get_userdata($user_info['id']);
 32         $name = $user_data->display_name;
 33     } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) {
 34         $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
 35     } else {
 36         $name = $user_info['email'];
 37     }
 38 
 39     $message = edd_get_email_body_header();
 40     $message .= edd_get_email_body_content( $payment_id, $payment_data );
 41     $message .= edd_get_email_body_footer();
 42 
 43     $from_name = isset( $edd_options['from_name'] ) ? $edd_options['from_name'] : get_bloginfo('name');
 44     $from_email = isset( $edd_options['from_email'] ) ? $edd_options['from_email'] : get_option('admin_email');
 45 
 46     $subject = apply_filters( 'edd_purchase_subject', isset( $edd_options['purchase_subject'] )
 47         ? trim( $edd_options['purchase_subject'] )
 48         : __( 'Purchase Receipt', 'edd' ), $payment_id );
 49 
 50     $subject = edd_email_template_tags( $subject, $payment_data, $payment_id );
 51 
 52     $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
 53     $headers .= "Reply-To: ". $from_email . "\r\n";
 54     $headers .= "MIME-Version: 1.0\r\n";
 55     $headers .= "Content-Type: text/html; charset=utf-8\r\n";
 56 
 57     // Allow add-ons to add file attachments
 58     $attachments = apply_filters( 'edd_receipt_attachments', array(), $payment_id, $payment_data );
 59 
 60     wp_mail( $payment_data['email'], $subject, $message, $headers, $attachments );
 61 
 62     if ( $admin_notice ) {
 63         do_action( 'edd_admin_sale_notice', $payment_id, $payment_data );
 64     }
 65 }
 66 
 67 /**
 68  * Email the download link(s) and payment confirmation to the admin accounts for testing.
 69  *
 70  * @since 1.5
 71  * @global $edd_options Array of all the EDD Options
 72  * @return void
 73  */
 74 function edd_email_test_purchase_receipt() {
 75     global $edd_options;
 76 
 77     $default_email_body = __( "Dear", "edd" ) . " {name},\n\n";
 78     $default_email_body .= __( "Thank you for your purchase. Please click on the link(s) below to download your files.", "edd" ) . "\n\n";
 79     $default_email_body .= "{download_list}\n\n";
 80     $default_email_body .= "{sitename}";
 81 
 82     $email = isset( $edd_options['purchase_receipt'] ) ? $edd_options['purchase_receipt'] : $default_email_body;
 83 
 84     $message = edd_get_email_body_header();
 85     $message .= apply_filters( 'edd_purchase_receipt', edd_email_preview_templage_tags( $email ), 0, array() );
 86     $message .= edd_get_email_body_footer();
 87 
 88     $from_name = isset( $edd_options['from_name'] ) ? $edd_options['from_name'] : get_bloginfo('name');
 89     $from_email = isset( $edd_options['from_email'] ) ? $edd_options['from_email'] : get_option('admin_email');
 90 
 91     $subject = apply_filters( 'edd_purchase_subject', isset( $edd_options['purchase_subject'] )
 92         ? trim( $edd_options['purchase_subject'] )
 93         : __( 'Purchase Receipt', 'edd' ), 0 );
 94 
 95     $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
 96     $headers .= "Reply-To: ". $from_email . "\r\n";
 97     $headers .= "MIME-Version: 1.0\r\n";
 98     $headers .= "Content-Type: text/html; charset=utf-8\r\n";
 99 
100     wp_mail( edd_get_admin_notice_emails(), $subject, $message, $headers );
101 }
102 
103 /**
104  * Sends the Admin Sale Notification Email
105  *
106  * @since 1.4.2
107  * @param int $payment_id Payment ID (default: 0)
108  * @param array $payment_data Payment Meta and Data
109  * @return void
110  */
111 function edd_admin_email_notice( $payment_id = 0, $payment_data = array() ) {
112     /* Send an email notification to the admin */
113     $admin_email   = edd_get_admin_notice_emails();
114 
115     $user_info = maybe_unserialize( $payment_data['user_info'] );
116 
117     if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) {
118         $user_data = get_userdata($user_info['id']);
119         $name = $user_data->display_name;
120     } elseif ( isset( $user_info['first_name'] ) && isset($user_info['last_name'] ) ) {
121         $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
122     } else {
123         $name = $user_info['email'];
124     }
125 
126     $admin_subject = apply_filters( 'edd_admin_purchase_notification_subject', __( 'New download purchase', 'edd' ), $payment_id, $payment_data );
127 
128     $admin_message = __( 'Hello', 'edd' ) . "\n\n" . sprintf( __( 'A %s purchase has been made', 'edd' ), edd_get_label_plural() ) . ".\n\n";
129     $admin_message .= sprintf( __( '%s sold:', 'edd' ), edd_get_label_plural() ) .  "\n\n";
130 
131     $download_list = '';
132     $downloads = maybe_unserialize( $payment_data['downloads'] );
133 
134     if ( is_array( $downloads ) ) {
135         foreach ( $downloads as $download ) {
136             $id    = isset( $payment_data['cart_details'] ) ? $download['id'] : $download;
137             $title = get_the_title( $id );
138             if ( isset( $download['options'] ) ) {
139                 if ( isset( $download['options']['price_id'] ) ) {
140                     $title .= ' - ' . edd_get_price_option_name( $id, $download['options']['price_id'], $payment_id );
141                 }
142             }
143             $download_list .= html_entity_decode( $title, ENT_COMPAT, 'UTF-8' ) . "\n";
144         }
145     }
146 
147     $gateway = edd_get_gateway_admin_label( get_post_meta( $payment_id, '_edd_payment_gateway', true ) );
148 
149     $admin_message .= $download_list . "\n";
150     $admin_message .= __( 'Purchased by: ', 'edd' )   . " " . html_entity_decode( $name, ENT_COMPAT, 'UTF-8' ) . "\n";
151     $admin_message .= __( 'Amount: ', 'edd' )         . " " . html_entity_decode( edd_currency_filter( edd_format_amount( $payment_data['amount'] ) ), ENT_COMPAT, 'UTF-8' ) . "\n\n";
152     $admin_message .= __( 'Payment Method: ', 'edd' ) . " " . $gateway . "\n\n";
153     $admin_message .= __( 'Thank you', 'edd' );
154     $admin_message = apply_filters( 'edd_admin_purchase_notification', $admin_message, $payment_id, $payment_data );
155 
156     $admin_headers = apply_filters( 'edd_admin_purchase_notification_headers', array(), $payment_id, $payment_data );
157 
158     $admin_attachments = apply_filters( 'edd_admin_purchase_notification_attachments', array(), $payment_id, $payment_data );
159 
160     wp_mail( $admin_email, $admin_subject, $admin_message, $admin_headers, $admin_attachments );
161 }
162 add_action( 'edd_admin_sale_notice', 'edd_admin_email_notice', 10, 2 );
163 
164 /**
165  * Retrieves the emails for which admin notifications are sent to (these can be
166  * changed in the EDD Settings)
167  *
168  * @since 1.0
169  * @global $edd_options Array of all the EDD Options
170  * @return void
171  */
172 function edd_get_admin_notice_emails() {
173     global $edd_options;
174 
175     $emails = isset( $edd_options['admin_notice_emails'] ) && strlen( trim( $edd_options['admin_notice_emails'] ) ) > 0 ? $edd_options['admin_notice_emails'] : get_bloginfo( 'admin_email' );
176     $emails = array_map( 'trim', explode( "\n", $emails ) );
177 
178     return apply_filters( 'edd_admin_notice_emails', $emails );
179 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0