I am stuck in a situation where the requirement is to create a custom email template for a particular product category, so that when any user buy product from that category he/she get that customised order email. Please help if anyone have any idea about how this can be achieved. Thanks in advance.
I am stuck in a situation where the requirement is to create a custom email template for a particular product category, so that when any user buy product from that category he/she get that customised order email. Please help if anyone have any idea about how this can be achieved. Thanks in advance.
Firstly extend WC_Email class to define the email header, subject, email template for content
secondly, add custom email class to the default WooCommerce email classes using woocommerce_email_classes filter, with trigger that calls terms
if ( has_term( 'Your Cat', 'product_cat', $item['product_id'] ) )
lastly, Create an email template to be used to generate email content for your custom email.
this answer to this question involves a lot of code, far too much for SO so you may want to do some reading like.
https://cloudredux/adding-sending-custom-woocommerce-email/
Whatever plugin you're using for ecommerce, there should be an email hook available to customize the emails.
For example, WooCommerce provides 9 different hooks in its "new order" email. Here's a visual reference.
Add a function that runs on the desired hook, and you can add conditional content. You'll have to find a way to identify "any product from a particular category" - pull order details, loop through the products, and if any of them is from that category, trigger your conditional content.
Further related reading: https://tommcfarlin/customizing-woocommerce-emails-hooks/