0

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?

2

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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