Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patrickfreitasdev/44bbf82f65422eb44fd34f95fb262e93 to your computer and use it in GitHub Desktop.
Save patrickfreitasdev/44bbf82f65422eb44fd34f95fb262e93 to your computer and use it in GitHub Desktop.
<?php
/**
* Adding [Urgent] to email subject if free shipping method woocommerce
*/
add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2);
function change_admin_email_subject( $subject, $order ) {
global $woocommerce;
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
//Check if shipping method exist.
if($order->get_shipping_method()){
//Get shipping name ref: https://stackoverflow.com/a/26174867
$shipping = reset( $order->get_items( 'shipping' ) )->get_method_id();
}
// Modify the subject if it is free shipping
if( isset( $shipping ) && $shipping === 'free_shipping'){
$subject = sprintf( '[URGENT] - [%s] New Customer Order (# %s) from Name %s %s', $blogname, $order->id, $order->billing_first_name, $order->billing_last_name );
}else{
// Default subject
$subject = sprintf( '[%s] New Customer Order (# %s) from Name %s %s', $blogname, $order->id, $order->billing_first_name, $order->billing_last_name );
}
return $subject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment