Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.