Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ko31/ad7b84f243808486c362711d1e294bcc to your computer and use it in GitHub Desktop.
Save ko31/ad7b84f243808486c362711d1e294bcc to your computer and use it in GitHub Desktop.
How to send an email manually using WooCommerce email templates.
<?php
// Load the WooCommerce email templates.
$wc_emails = WC()->mailer()->get_emails();
/**
* You can specify which template mail is to be sent from the following array elements.
* 'WC_Email_New_Order'
* 'WC_Email_Cancelled_Order'
* 'WC_Email_Failed_Order'
* 'WC_Email_Customer_On_Hold_Order'
* 'WC_Email_Customer_Processing_Order'
* 'WC_Email_Customer_Completed_Order'
* 'WC_Email_Customer_Refunded_Order'
* 'WC_Email_Customer_Invoice'
* 'WC_Email_Customer_Note'
* 'WC_Email_Customer_Reset_Password'
* 'WC_Email_Customer_New_Account'
*/
// Set the recipeent.
$wc_emails['WC_Email_New_Order']->recipient = 'sample@example.com';
// If you want to change the email type, you can set it from 'html', 'multipart', or 'plain'.
//$wc_emails['WC_Email_New_Order']->email_type = 'plain';
// Trigger the sending of an email to the order ID.
$order_id = 1;
$wc_emails['WC_Email_New_Order']->trigger( $order_id );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment