The break is in the wrong place. When you put a break; in a loop (foreach), it quits the loop right at that point. You have your break before you set the $subject value so you’re quitting the loop before the $subject is set.
Set the subject, then break.
Also, your code snippet is missing the add_filter() call that triggers this filter function. This needs to be hooked to woocommerce_email_subject_new_order, the same as in the examples you linked to.
add_filter('woocommerce_email_subject_new_order', 'custom_admin_email_subject', 1, 2);
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' );
break;
}
}
return $subject;
}
Related Posts:
- WooCommerce lost password reset flow not working with SendGrid (redirect loop)
- Preventing WooCommerce email sending only on particular conditions
- woocommerce fail to replace template string in email title [closed]
- WooCommerce: display text instead of raw checkbox value email
- Editing Header Titles of each details in woocommerce Order Email [closed]
- Woocommerce : How to attach an custom attachment with customer-processing-order.php email template [closed]
- WooCommerce email text based on category && shipping zone && payment method [closed]
- WooCommerce: Email Notifications
- woocommerce_email_attachments filter arguments [closed]
- WordPress ‘on behalf of’ email
- WooCommerce: The model of e-mail is displaying only the html, not css [closed]
- How do I hide the purchase note in the WooCommerce ‘order completed’ email?
- Add custom order meta to Order Completed email
- Woocommerce: Prevent sending of email when order is “Completed”
- How to add a user custom field into Woocommerce emails?
- WooCommerce order complete email logic
- woocommerce email template detect email recipient
- Adding extra email address who receives email like admin – woocommerce
- Add shipping address to Woocommerce order emails [closed]
- Send email notifications to a defined email address depending if a product in order has a specific TAG [closed]
- Woocommerce emails from gmail not being sent
- Send admin new order email to logged in user as well
- Create new email in WooCommerce
- How to check if woocommerce_order_item_name is use in email?
- WordPress woocommerce new order email not working
- Custom Email via Hook only for completed order
- Access custom meta_data in processing order email
- How to add (and change the font of) the short product description to order page and customer’s new order e-mail [closed]
- How to send Woocommerce Customer Details (Name, Email and Phone Number) to Admin upon signup
- How to change lost password email text using custom plugin wordpress?
- Using admin email in billing address
- Forgot password flow does not work, getting email with a link but after clicking link it’s not working
- Send a different “thank you” email based on payment method
- Customer Email Address
- Adding time of order to Admin email for new order
- how to add custom reviews button in woocommerce order complete generated mail
- How to add coupon expiry date into the followup emails?
- Conditional email recipient based off Shipping Method [closed]
- Manual Woocommerce Complete order Emails
- Turkish Character Problem on mailing
- How to override email text New Customer Order?
- Woo-Commerce new order email no style attached
- WooCommerce – How to add a custom field to only a specific email template [closed]
- Insert a custom field as a second email address to a completed order in WooCommerce
- Woocommerce admin order email customize – remove product short description
- Getting the gallery images from products in woocommerce?
- Get product details by url key in WordPress woocommerce
- Reverse engineering of WooCommerce Storefront filters
- Use WooCommerce function in other WordPress plugin
- Add product description (content) to WooCommerce customer processing order email
- Woocommerce: How to remove page title from storefront theme homepage
- Remove checkout fields with Woocommerce depending on one of several shipping methods
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- Replace one coupon to another after coupon added
- WooCommerce Multi-Currency shortcode not working
- rating, share and review issue for single WooCommerce page
- Custom PLU field in woocommerce email
- Keep getting Notice: Trying to get property of non-object in …\wp-includes\post.php on line 4153 when generating woocommerce coupon
- How to subscribe free subscription on user registration in woocommerce subscription plugin?
- Woocommerce cart page – Add “Free” to the shipping label when shipping is 0
- Change product in cart when billing country is changed
- Additional fields on Woocommerce’s rating system
- Woocommerce product image [closed]
- Question on WooCommerce Syntax
- Tax are not showing on order while placing order with REST API
- woocommerce_new_product action doesn’t fire
- Change The Woocommerce Product Categories Dropdown Widget Placeholder Text
- minimum order item for certain products exempting 2 other products (in bulk)
- Is it possible to checkout with 2 different shipping options on a single order? [closed]
- Undo WooCommerce CSV import
- Woocommerce Advanced Shipping (WAS) condition is not being called when selecting “Ship to different address” [closed]
- Strip string from $_product->get_title() to get a cleaner mini-cart
- WooCommerce Product Table Conditional styling
- Product page attributes dropdown show price
- Smart Design for Blog + Woocommerce + LearnDash + Forum/Bodyboss
- Ajax add to cart not updating Elementor mini cart totals
- WooCommerce – 500k Jump in Order Number?
- Need help with woocommerce roles
- Change WooCommerce product and variation prices programatically without affecting performance
- Can I use taxonomies to make a multistore with woocommerce?
- Why does wc_get_products($arg) return no products when $arg = ‘average_rating’ => 5.0
- woocommerce_sessions – Table does not exist
- How update price for variable product
- Woocommerce add 15% discount to a product if quantity is greater than or equal to 6
- Related products based on keywords
- Send default WooCommerce email when switching from custom order status
- How to set up a single product shop with woocommerce? Skipping the product archive
- I’m trying to display product categories on each product in the list
- Cross-sells on WooCommerce product page
- Admin Order adding an extra product on add_line_item
- Woocommerce update cart
- Get WP All Export row ID
- WooCommerce – missing products when viewed by tag
- Quotes not rendering properly in WooCommerce settings API [closed]
- Hiding all products except for one in wordpress admin panel
- Edit woocommerce subscription email
- cannot create product attribute (taxonomy) and add terms on the same execution
- How do I get my image for my product to not be blurry
- Product Variation Auto Select when only one 1 and mark the option [closed]
- Resending woo-commerce order emails from frontend