I would like the Email Subject line for the admin email to change based on the product category. I've looked at ALL similar stack overflow 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() ) ) {
break;
$subject = sprintf( 'Category 1 Email Subject Line' );
}
}
return $subject;
}
add_filter('woocommerce_email_subject_new_order', 'custom_admin_email_subject', 1, 2);
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