Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In Woocommerce 2.0, I need to print a custom field on the New Order email.

It is a meta/custom field each product has named "longsku" (which is normally hidden.)

This needs to be included in the email-order-items.php email template but I am not certain what syntax is necessary to print it.

For instance, variations are printed like so within the email template:

echo ($item_meta->meta) ? '<br/><small>' . nl2br( $item_meta->display( true, true ) ) . '</small>' : '';

Does anyone have experience printing custom fields from products (not from actual checkout) in the email templates?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

the longsku is regular wordpress post meta, so you can simply call that with get_post_meta.

get_post_meta takes three arguments:

  • post_id (which is already available in $_product)]
  • meta key ('longsku' in your case)
  • and a boolean to return a single string (true). if not set, it returns an array, but since the meta key is just a single value you can use true

this should do the trick for your longsku:

echo get_post_meta($_product->id,'longsku',true);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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