Notify Extra People of EDD Sales by Category
Adds extra recipients to the Easy Digital Downloads sale notification when an order contains downloads from a category, such as a partner or course author.
Opens WPIDE on
Code
$wpide_edd_category_emails = array( // Download category slug => email address.
'themes' => '[email protected]',
'courses' => '[email protected]',
);
add_filter( 'edd_admin_notice_emails', function ( $emails, $email = null ) use ( $wpide_edd_category_emails ) {
$order_id = ( $email instanceof \EDD\Orders\Order ) ? (int) $email->id : 0; // EDD passes the order for sale notifications.
if ( ! $order_id || ! function_exists( 'edd_get_order_items' ) ) {
return $emails;
}
foreach ( edd_get_order_items( array( 'order_id' => $order_id, 'number' => 100 ) ) as $item ) {
foreach ( $wpide_edd_category_emails as $slug => $address ) {
if ( is_email( $address ) && has_term( $slug, 'download_category', $item->product_id ) ) {
$emails[] = $address;
}
}
}
return array_values( array_unique( (array) $emails ) );
}, 10, 2 );
Notes
The usual sale notification recipients still get every email.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.