-4

What I am trying to do

I am adding a custom field to a WooCommerce email template, however I am trying to make the custom field only appear in one custom email template instead of all of them however i am struggling to achieve this. The template is called: customer-completed-order.php

What I have so far

Using my child theme, i have copied the template from the original WooCommerce folder to soulmedic-child/woocommerce/emails/customer-completed-order.php

I have successfully made the custom field appear in all the original email templates using the following code in functions.php:

add_filter( 'woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys');

function my_custom_checkout_field_order_meta_keys( $keys ) {
$keys[] = 'Postage Tracking Number';
return $keys;
}

I have checked through available hooks and have tried adding the following to the filter list, however, this did not worked: woocommerce_email_heading_customer_completed_order

I have searched through loads and loads of other posts however have not found anyone else who has managed to do this.

I have attempted to add code directly to the email template however as i am already specifying the custom fields in functions.php it still adds the field to all email templates. I tried putting the code only in the email template however this broke the template.

Could someone show me what I need to do to allow the information in the custom field to only appear on that specific template and no where else?

closed as off-topic by Mark Kaplun, RRikesh, birgire, bueltge, Howdy_McGee Aug 31 '16 at 14:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

Best way would be to save a custom version of the theme template into your theme folder. That way you can customise that individual email and include the custom field.

Can do this by copying the customer-completed-order.php from WooCommerce into a /woocommerce/templates/ folder in your theme.

More info on the WooCommerce docs: Template Structure + Overriding Templates via a Theme

  • Hi, im not sure that you understand the question, i am already running my own custom templates in my own child theme, this was never the problem, the question was how can i make the custom content only appear in a single email instead of all of them. – Ultra_charge Aug 26 '16 at 12:41
0

I discovered that the original method i had created was actually fine for my purposes, the reason is the custom field i would like displayed in the email actually only appears if the field has been populated with data, if the field is blank, then it is not included in any other email templates.

As we are only populating the custom field with data after we have already sent the other order emails, i do not need to add any more filters.

Not the answer you're looking for? Browse other questions tagged or ask your own question.