Last active
February 27, 2016 18:01
-
-
Save amdrew/1e548cb7934b2678c1b2 to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Milestone Sale Alerts
This file contains 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 | |
/** | |
* Milestone Sale Alerts | |
* Be notified when a specific download is sold X times. | |
*/ | |
function sumobi_edd_milestone_sales_alert( $purchase_id ) { | |
// ID of download to check | |
$download_id = 8; | |
// sales milestone to reach | |
$milestone = 100; | |
// email/s to send the notification to. Add more emails to array if neccessary | |
$send_to = get_option( 'admin_email' ); | |
// get the current number of sales for the download | |
$sales = get_post_meta( $download_id, '_edd_download_sales', true ); | |
// message to be included in the email | |
$message = sprintf( 'Congratulations, you have just reached your milestone of %s sales for %s! View this sale here: %s', $milestone, get_the_title( $download_id ), admin_url( 'edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $purchase_id ) ); | |
// send email is milestone is reached | |
if ( $milestone == $sales ) { | |
wp_mail( $send_to, 'Milestone reached!', $message ); | |
} | |
} | |
add_action( 'edd_complete_purchase', 'sumobi_edd_milestone_sales_alert' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment