Custom Admin Email Subject for Woocommerce (3.8.0) Orders


I would like the Email Subject line for the admin email to change based on the product category.
I’ve looked at ALL similar stackoverflow questions and NONE of them work for woocommerece 3.8.0
(see this and this).

What I have is this

function custom_admin_email_subject( $subject, $order ) {
    global $woocommerce;
    foreach($order->get_items() as $item_id => $item ){
        if ( has_term( 'Category 1 Name', 'product_cat' , $item->get_product_id() ) ) { 
            $subject = sprintf( 'Category 1 Email Subject Line' );
    return $subject;

My code simply returns the default email subject line for new orders (which is set in woocommerce/settings/email).
I can’t figure out why my function does not recognize category names.

Can anyone tell me what is wrong with my code?

I am placing this code in my child-theme/functions.php file
I am running woocommerce 3.8.0 and wordpress 5.3

, , , , david lee 3 years 2019-11-19T14:14:58-05:00 0 Answers 95 views 0

Leave an answer