Created
May 25, 2016 12:55
-
-
Save zarankumar/56a1317b2a964e3b0e32af5df7c6b541 to your computer and use it in GitHub Desktop.
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
// Add Downloadable Products to Woocommerce Completed Order & Invoice Emails as Attachments | |
add_filter( 'woocommerce_email_attachments', 'woocommerce_emails_attach_downloadables', 10, 3); | |
function woocommerce_emails_attach_downloadables($attachments, $status, $order) { | |
if ( ! is_object( $order ) || ! isset( $status ) ) { | |
return $attachments; | |
} | |
if ( empty( $order ) ) { | |
return $attachments; | |
} | |
if ( ! $order->has_downloadable_item() ) { | |
return $attachments; | |
} | |
$allowed_statuses = array( 'customer_completed_order' ); | |
if ( isset( $status ) && in_array( $status, $allowed_statuses ) ) { | |
foreach ( $order->get_items() as $item_id => $item ) { | |
foreach ( $order->get_item_downloads( $item ) as $download ) { | |
$attachments[] = str_replace( content_url(), WP_CONTENT_DIR, $download['file'] ); | |
} | |
} | |
} | |
return $attachments; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment