Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Custom Field at Checkout Page to Appear in Notifications Email

Custom Field at Checkout Page to Appear in Notifications Email

Shawn_Gay
Visitor
1 0 0

Summary: Within my `Checkout.Liquid` file, I am inserting a custom field programmatically. I am trying to set that variable as an attribute to be used in the Notification Order Confirmation email process. However, that attribute is not being displayed within the email.

 

Context:

I initially followed this walkthrough/tutorial to create my foundation of code.

 

I am appending an Text Input with the HTML Attributes:

 

 name="checkout[attributes][oppField]" value="{{ checkout.attributes["oppField"] }}"

 

 

I know this works, because after the HTML Form is submitted, this value persists after returning to this page.

 

To Note:

I noticed in the Order documentation for Attributes It mentions "Attributes are collected with the cart."

In my `Cart-Template.Liquid` I read for `cart.attributes["oppField"]` which returns the value I inputted at checkout. So these are referring the same variable/object.

 

My Issue:

At Settings > Notifications > Edit Order Confirmation 

I have tried two blocks of code to display this value, however the value is NOT displaying for either attempt:

// Block 1
{% if order.attributes %}
  {% for attribute in order.attributes %}
    {% if attribute.first == 'oppField' %}
      <h5>t1: {{ attribute.first }}: {{ attribute.last }}</h5><br>
    {% endif %}
  {% endfor %}
{% endif %}

// Block 2
{% if order.attributes['oppField'] and order.attributes['oppField'] != '' %}
  <h5>t2: {{ order.attributes['oppField'] }}</h5>
{% endif %}

Could my problem be (Protentional):

  • Trying to look for, `{% if attribute.first == 'oppField' %}`?
  • Trying to read from `order.attributes` rather than just `attributes`?
  • Some kind of syntax error?

 

Thank you for any response or ideas, because I am all out!

 

 

 

Reply 1 (1)

Sinchain
Shopify Partner
69 15 20

Hello @Shawn_Gay ,

 

Thank you for reaching out to the Shopify community.

 

You can utilize attributes directly instead of order.attributes in the order confirmation emails. Here is the code which will render the direct value of attributes in the notification emails.

 

{% for attribute in attributes %}
    Attribute Key: {{ attribute | first }}
    Attribute Value: {{ attribute | last }}
{% endfor %}

 


Quick reference link: Notification variables reference 

Do give it a try and let me know if this was helpful.

Sinchain || Recurpay Subscriptions

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution