woocommerce offtopic - Custom email template for a specific product category

admin2025-06-05  3

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.

Share Improve this question asked Jun 15, 2017 at 10:14 Pankaj ThakurPankaj Thakur 11 silver badge2 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

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/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749063387a316039.html

最新回复(0)