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
- Display WooCommerce only in stock sizes product attribute on shop page
- Remove “Choose An Option” on Product Variation & Auto Select Instead
- check if current url/page equals checkout page [closed]
- Mini cart in header using divi is not getting updated on changing the cart items count:
- Woocommerce Product Price Inserted programmatically doesn’t get displayed In Single Product Page
- How to Order by random on a SQL query
- Move add to cart in Woocommerce
- Separate Categories from WC Product loop when display type is set to both on the category
- Exclude products with a stock lower than the low stock threshold from the shop loop [closed]
- Remove Order List Row Link in WooCommerce Admin?
- Set a condition based on WooCommerce checkout city field while placing order
- How do I hide out of stock products from homepage but not from catalog?
- Woocommerce order processing email subject not changing
- Different translations for the same plugin inside a multisite
- WooCommerce – Display nested list of all subcategories on archive-product.php
- Woocommerce Porto Theme Hide Selected Categroy for Breadcrumbs
- WooCommerce product archive url without value / all values
- WooCommerce orderby template disappears and not longer works on search page
- Woocommerce variations as a list [closed]
- Sort & Display WooCommerce Product Attributes by Order
- wp_set_object_terms being undone
- How to search variable product by its variation id in woocommerce admin product search box?
- Hide inventory message on product page based on available stock quantity
- Different Templates for Woocommerce Parent and Child Sub Categories
- Clients with empty username are not receiving request new password email
- how can i add an additional action into woocommerce admin order page through my plugin?
- Woocommerce changing add to cart button text as icon [closed]
- Display data when category is empty
- Disable woocommerce PLACE ORDER button if user selected products that are not available for international delivery
- Remove sale signs from site in branded? [closed]
- Create a regular post for every WooCommerce order
- Hooks For Design variation in woo commerce single product page
- Dokan stock management
- Woocommerce : How to automatically input the same email for every order?
- Deregister dequeue JS scripts except on 1 product page
- Woocommerce – how to round up all prices to end in .99
- How do I disable “Flat Rate” radio button and remain with other shipping method in woocommerce
- How to add woocommerce product price filter widget to other page
- Remove Stripe Woocommerce Credit Card Icons (and replace with image)
- How to add external product url to woocommerce from a metadata by function.php
- Unable to call woocommerce hook in my custom php file
- Two types of product categories on shop page
- How to send an automatic email to a custom field in Woocommerce order meta 2 weeks after a product is bought
- Woocommerce cart table too wide [closed]
- WooCommerce CSV Image URL Creates Additional Images in Media Folder
- Custom changes performed on WP + WooCom site on maintenance subdomain. How to perform a migration to a main domain?
- How to restrict type/size of file uploads in any plugin?
- In woocommerce some products have empty options, but how to check this
- Woocommerce Add to Cart function
- WooCommerce – doesn’t show product when using woocommerce.php [closed]
- How to show woocommerce login / registration form in modal
- Add Additional 3 buttons next to “Add to cart” button in woocommerce product page
- How do I remove the recurring total from thank you for your order email?
- Display product categories + child-categories on a single product page
- I want to Display custom woocomerce meta box in orders list