Skip to content

Instantly share code, notes, and snippets.

@melvinstanly
Last active March 11, 2021 22:36
Show Gist options
  • Save melvinstanly/96aafb85379c15fe08d8a2f7719b29dc to your computer and use it in GitHub Desktop.
Save melvinstanly/96aafb85379c15fe08d8a2f7719b29dc to your computer and use it in GitHub Desktop.
Easy tricks in woocommerce emails
<?php
// Change email titles (Email template name in Woocommerce Settings Admin)
// woocommerce -> settings -> emails
add_filter( 'woocommerce_email_title', 'change_woocommerce_email_title', 10, 2 );
function change_woocommerce_email_title( $email_title, $email ){
$domain = "woocommerce"; // The text domain
switch ($email->id) {
case 'new_order':
$email_title = __("New Order Email", $domain);
break;
case 'cancelled_order':
$email_title = __("Cancelled Order Email", $domain);
break;
case 'failed_order':
$email_title = __("Failed Order", $domain);
break;
case 'customer_on_hold_order':
$email_title = __("Customer On Hold Order Email", $domain);
break;
case 'customer_processing_order':
$email_title = __("Customer Processing Order Email", $domain);
break;
case 'customer_completed_order':
$email_title = __("Customer Completed Order Email", $domain);
break;
case 'customer_refunded_order':
$email_title = __("Customer Refunded Email", $domain);
break;
case 'customer_invoice':
$email_title = __("Customer Invoice Email", $domain);
break;
case 'customer_note':
$email_title = __("Customer note Email", $domain);
break;
case 'customer_reset_password':
$email_title = __("Customer Reset Password Email", $domain);
break;
case 'customer_new_account':
$email_title = __("Customer New Account Email", $domain);
break;
}
return $email_title;
}
<?php
//Add additional receipient for new order emails [email address option from custom field in checkout]
// Note that custom field in checkout is saved to order meta
// change $order_status to add recepient to different 'emails woocommerce_email_recipient_.$order_status'
add_filter( 'woocommerce_email_recipient_new_order', 'add_recipient', 10, 2 );
function add_recipient( $recipient, $order ){
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
if(isset($order_id)){
$consultant_name = get_post_meta( $order_id, 'custom_field_name_here', true );
if(isset($consultant_name)){
$recipient .= ','. $consultant_name;
}
}
return $recipient;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment