Skip to content

Instantly share code, notes, and snippets.

@bekarice
Last active October 20, 2022 11:25
Show Gist options
  • Save bekarice/50900986dc58f00ec765 to your computer and use it in GitHub Desktop.
Save bekarice/50900986dc58f00ec765 to your computer and use it in GitHub Desktop.
Add customer name to WooCommerce Admin New Order Email subject
<?php // only copy this line if needed!
/**
* Adds customer first and last name to admin new order email subject.
*
* @param string $subject email subject
* @param \WC_Order $order the order object for the email
* @return string updated subject
*/
function skyverge_add_customer_to_email_subject( $subject, $order ) {
$subject .= ' from ' . $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
return $subject;
}
add_filter( 'woocommerce_email_subject_new_order', 'skyverge_add_customer_to_email_subject', 10, 2 );
@Uriel1339
Copy link

That is outdated. Please see revised below:

// Adds customer first and last name to admin new order email subject
function skyverge_add_customer_to_email_subject( $subject, $order ) {
	$subject = '[J.N. Equipment Superstore] New Customer Order - (# ' . $order->get_order_number() . ') from ' . $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
	return $subject;
};
add_filter( 'woocommerce_email_subject_new_order', 'skyverge_add_customer_to_email_subject', 10, 2 );

Giving quite some PHP errors / notices since WooCommerce 3.0 if you don't update it to '$order->get_...' :)

@2TheMooon
Copy link

if i want product name Was Sold how to do that?

@td8000
Copy link

td8000 commented Oct 20, 2022

hello, same question would be important for me. the code works fine, just the product name must be added to the subject.
How can that be done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment