0

Added custom field ('field_secretkey') under Commerce - Product variation (admin/commerce/config/product-variation-types).

I am able to get this value in Orders view by adding the "Product variation" relationship.

I just want to print this value in order confirmation email (commerce-order-receipt.html.twig) It can have multiple items with different values.

Please advice.

Example:


No | Product Name | Custom field


1 | Product 01 | XYUSNMAI

2 | Product 02 | AYUSSAAA

3 | Product 03 | PAUSNPPP


enter image description here


Updated: RESOLVED - TRY BELOW

URL - {{ order_item.getPurchasedEntity.field_custom_field.0.uri }}

TITLE - {{ order_item.getPurchasedEntity.field_custom_field.0.title }}

0

You should be able to get the product from the order which is available in the template.

I think that this will give you the products:

{% for order_item in order_entity.getItems %}
  {{ order_item }}// The product
  {{ order_item.FIELD_NAME.value }}// The field value
{% endfor %}

Otherwise you must add the product in a preprocess function.

  • Thank you! The field type is 'Link", Attached screenshot. I have tried with above code and it is not working. Can you help me to write preprocess function. – shanidkv Jun 30 '19 at 8:42
  • Have you tried to kint order_item, because to get link values you don't have to say .value but .0.uri.value or something like that. – user72672 Jun 30 '19 at 8:49
  • {{ order_item.field_custom_field }} should render the field. – user72672 Jun 30 '19 at 8:50

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.