wordpress send email code example

Example: wordpress send email WC_Email

$wc_emails = WC_Emails::instance();
$emails    = $wc_emails->get_emails();
if ( isset( $emails['WC_Email_Customer_Processing_Order'] ) && is_object( $emails['WC_Email_Customer_Processing_Order] ) ) {
$email = $emails['WC_Email_Customer_Processing_Order'];
};
$order     = wc_get_order( $order_id );
if ( isset( $email ) ) {
// Make sure gateways are running in case the email needs to input content from them.
WC()->payment_gateways();
// Make sure shipping is running in case the email needs to input content from it.
WC()->shipping();
$email->object = $order;
$email->find['order-date']   = '{order_date}';
$email->find['order-number'] = '{order_number}';
if ( is_object( $order ) ) {
$email->replace['order-date']   = wc_format_datetime( $email->object->get_date_created() );
$email->replace['order-number'] = $email->object->get_order_number();
// Other properties
$email->recipient = $email->object->get_billing_email();
}
if ( $email->get_recipient() ) {
$email->send( $email->get_recipient(), $email->get_subject(), $email->get_content(), $email->get_headers(), $email->get_attachments() );
}

Tags:

Misc Example