Created
September 12, 2014 02:42
-
-
Save amdrew/2325e1926b01b5dd54e6 to your computer and use it in GitHub Desktop.
Easy Digital Downloads + EDD Commissions extension - Include the customer's email address for the vendor in the email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sumobi_edd_commissions_email_alert( $user_id, $commission_amount, $rate, $download_id, $commission_id, $payment_id ) { | |
global $edd_options; | |
/* send an email alert of the sale */ | |
$from_name = isset( $edd_options['from_name'] ) ? $edd_options['from_name'] : get_bloginfo( 'name' ); | |
$user = get_userdata( $user_id ); | |
$email = $user->user_email; // set address here | |
// get customer information | |
$user_info = edd_get_payment_meta_user_info( $payment_id ); | |
// customer's email address | |
$customer_email_address = $user_info['email']; | |
// subject | |
$subject = __( 'New Sale!', 'eddc' ); | |
$message = __( 'Hello', 'eddc' ) . "\n\n" . sprintf( __( 'You have made a new sale on %s!', 'eddc' ), stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) ) . ".\n\n"; | |
$variation = get_post_meta( $commission_id, '_edd_commission_download_variation', true ); | |
// email message | |
$message .= __( 'Item sold: ', 'eddc' ) . get_the_title( $download_id ) . ( ! empty( $variation ) ? ' - ' . $variation : '' ) . "\n\n"; | |
$message .= __( 'Amount: ', 'eddc' ) . " " . html_entity_decode( edd_currency_filter( edd_format_amount( $commission_amount ) ) ) . "\n\n"; | |
$message .= __( 'Commission Rate: ', 'eddc' ) . $rate . "%\n\n"; | |
$message .= __( 'Customer\'s Email Address: ', 'eddc' ) . $customer_email_address . "\n\n"; | |
$message .= __( 'Thank you', 'eddc' ); | |
$message = apply_filters( 'eddc_sale_alert_email', $message, $user_id, $commission_amount, $rate, $download_id ); | |
if ( class_exists( 'EDD_Emails' ) ) { | |
EDD()->emails->__set( 'heading', $subject ); | |
EDD()->emails->send( $email, $subject, $message ); | |
} else { | |
$from_name = apply_filters( 'eddc_email_from_name', $from_name, $user_id, $commission_amount, $rate, $download_id ); | |
$from_email = isset( $edd_options['from_email'] ) ? $edd_options['from_email'] : get_option( 'admin_email' ); | |
$from_email = apply_filters( 'eddc_email_from_email', $from_email, $user_id, $commission_amount, $rate, $download_id ); | |
$headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; | |
wp_mail( $email, $subject, $message, $headers ); | |
} | |
} | |
remove_action( 'eddc_insert_commission', 'eddc_email_alert', 10, 6 ); | |
add_action( 'eddc_insert_commission', 'sumobi_edd_commissions_email_alert', 10, 6 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment