Skip Navigation

[Resolved] Get Toolset product custom field value echo in Woocommerce order email with url

This support ticket is created 5 years, 3 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by Nigel 5 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1355389

Tell us what you are trying to do?

Each of the product have a Toolset custom field value. That value is a PDF uploaded via custom field. We need this link to be accessible directly from order email confirmation.

I tried this kind of stuff (and a lot of other combinations 🙂 in email-order-items.php and functions.php

echo 'Download PDF';

So:

How to echo a custom field value of a product in an order email woocommerce?

#1355435

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I suspect the problem is as simple as Types custom fields are stored with a prefix of 'wpcf-', so if the slug of your custom field is 'my-custom-field' then the key in wp_postmeta is actually 'wpcf-my-custom-field', which is what you should use in your get_post_meta call.

Is that the case?

#1356159

Thank you for reply,

Well, also tried with wpcf- prefix.

#1356771

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You are using this:

get_post_meta( $product, 'my-custom-field', false )

The first argument of get_post_meta is the post ID: https://developer.wordpress.org/reference/functions/get_post_meta/

But $product is not the post ID.

Looking at the code of the email-order-items.php template it looks like you should be able to use $item['product_id'] for the post ID.

#1359377

Thank you Nigel,

I will try and let you know.

#1359593

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sure, please do.