Anfelipe
Anfelipe

Reputation: 771

How to detect email recipient in Woocommerce template partial?

I'm trying to customize email templates in woocommerce so the customer gets the normal email notification with his new order data with some little customization, and the admin gets the new order email notification with some more detailed data of the order. Woocommerce provides several email templates and hooks to customize this, and in fact, there's a template called admin-new-order.php and customer-processing-order.php, but there's something particular that doesn't have that and it's the email-order-items.php file, because this is common to both templates (Like a "partial").

This file fetchs order items with name, quantity and price columns, and print it in the email template. I managed to include some info in those column cells, but I need to decide whether to include certain info if the recipient is a customer or is admin, how can I query for the recipient of the parent template of this order items (products) table?

Thank you so much

Upvotes: 0

Views: 819

Answers (1)

Anfelipe
Anfelipe

Reputation: 771

I solved it in a non-so-pretty way, since there's two template files (admin-new-order.php and customer-processing-order.php) that call a function that uses the template child (email-order-items.php) where I needed to know if the "caller" template was for admin of for customer. I set a global variable before calling the function that prints the products table, and inside that table I conditionally put some info or not.

If there's a better, cleaner way, I'm listening...

Upvotes: 0

Related Questions