Add users to the email recipients in WooCommerce programmatically

/**
 * Adds all administrators and shop managers to the "Completed order" email recipients.
 *
 * @see https://wpcodebook.com/woocommerce-add-users-email-recipients/
 * @see https://github.com/woocommerce/woocommerce/blob/9.3.3/plugins/woocommerce/includes/emails/class-wc-email.php#L446
 */
add_filter( 'woocommerce_email_recipient_customer_completed_order', function ( $recipient, $object, $email ) {
	$users  = get_users( array( 'role__in' => array( 'administrator', 'shop_manager' ) ) );
	$emails = implode( ',', array_unique( wp_list_pluck( $users, 'user_email' ) ) );
	$emails = implode( ',', array( $recipient, $emails ) );
	return $emails;
}, 10, 3 );

To add recipients to other emails, replace customer_completed_order (in woocommerce_email_recipient_customer_completed_order) with one of these:

cancelled_order
customer_completed_order
customer_invoice
customer_new_account
customer_note
customer_on_hold_order
customer_partially_refunded_order
customer_processing_order
customer_refunded_order
customer_reset_password
failed_order
new_order

Leave a Comment