Skip Navigation

[Resolved] Adding data from custom field to Woocommerce order e-mail

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to include information from a custom field in my WooCommerce Order email by adding some code with types_render_field().

Solution: I'm not sure how to modify these email templates, but I can explain how to use the types_render_field function.
- In order to get a Types custom field value from an order post you need to supply the order ID to the types_render_field function's parameters array.
- You need to use the "wpcf-" prefix applied to the field slug.
- You should specify the raw output type to prevent extra markup from being applied to the output.

Example:

[php]
TRACK YOUR ORDER

[php]

Replace 12345 with the Order ID, or a variable or shortcode that provides that ID.

Relevant Documentation: https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by nereaD 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#591215

Hello there,

I added a custom field (order-tracking) to all my orders in Wocommerce, where I put a tracking number.

I edited my "customer-completed-order" template (which is sent to the customer) and added this code:

<a href="<?php echo types_render_field( 'order-tracking', array() ); ?>">TRACK YOUR ODER</a>

It is not working at all. I guess there is a proper way to do it?

Thank you.

#591349

Hi, I'm not the best resource for information about how to use WooCommerce email templates, but I can tell you how to use the types_render_field function in general.
- In order to get a Types custom field value from an order post you need to supply the order ID to the types_render_field function's parameters array.
- You need to use the "wpcf-" prefix applied to the field slug.
- You should specify the raw output type to prevent extra markup from being applied to the output.

Example:

<a href="<?php echo types_render_field( 'wpcf-order-tracking', array('id' => 12345, 'output' => 'raw') ); ?>">TRACK YOUR ORDER</a>

Replace 12345 with the Order ID, or a variable or shortcode that provides that ID.

More information about the types_render_field shortcode here:
https://toolset.com/documentation/customizing-sites-using-php/functions/

#591499

Thank you very much for your help!