Show order downloads in admin new order email notification in WooCommerce on child sites.
Snippet Type
Execute on Child Sites
Snippet
// Let 3rd parties unhook via this hook.
function action_woocommerce_email( $emails ) {
// Removes a function from a specified action hook.
remove_action( 'woocommerce_email_order_details', array( $emails, 'order_downloads' ), 10 );
// Hooks a function on to a specific action.
add_action( 'woocommerce_email_order_details', 'action_woocommerce_email_order_details', 9, 4 );
}
add_action( 'woocommerce_email', 'action_woocommerce_email', 10, 1 );
/**
* Show order downloads in a table.
*
* @since 3.2.0
* @param WC_Order $order Order instance.
* @param bool $sent_to_admin If should sent to admin.
* @param bool $plain_text If is plain text email.
* @param string $email Email address.
*/
function action_woocommerce_email_order_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
// Only for 'New Order' email notifications
if ( $email->id == 'new_order' ) {
$sent_to_admin = false;
}
$show_downloads = $order->has_downloadable_item() && $order->is_download_permitted() && ! $sent_to_admin && ! is_a( $email, 'WC_Email_Customer_Refunded_Order' );
if ( ! $show_downloads ) {
return;
}
$downloads = $order->get_downloadable_items();
$columns = apply_filters(
'woocommerce_email_downloads_columns',
array(
'download-product' => __( 'Product', 'woocommerce' ),
'download-expires' => __( 'Expires', 'woocommerce' ),
'download-file' => __( 'Download', 'woocommerce' ),
)
);
if ( $plain_text ) {
wc_get_template(
'emails/plain/email-downloads.php',
array(
'order' => $order,
'sent_to_admin' => $sent_to_admin,
'plain_text' => $plain_text,
'email' => $email,
'downloads' => $downloads,
'columns' => $columns,
)
);
} else {
wc_get_template(
'emails/email-downloads.php',
array(
'order' => $order,
'sent_to_admin' => $sent_to_admin,
'plain_text' => $plain_text,
'email' => $email,
'downloads' => $downloads,
'columns' => $columns,
)
);
}
}