Where is the data for custom fields stored?

Customer Fields stores custom data in two places; the app's database and Shopify’s customer metafields.

When a customer record is created or updated by Customer Fields, and the data being saved contains values for custom data columns, then our app will store this additional information on the Customer resource/object in Shopify using metafields. A customer's metafield data can be accessed in several ways:

  1. Directly in the Shopify admin using metafield definitions

  2. Via Shopify's Admin APIs

  3. On the storefront or customer-facing emails using Liquid

The rest of this help article focuses on #3 - accessing the metafield data from Customer Fields using Liquid.

Note: Metafields are only used for custom fields and data columns

Please keep in mind that the data for standard fields and data columns (e.g. first_name, email, phone, etc) will be saved to the normal fields and properties within Shopify. We suggest using Shopify's documentation if you need help displaying standard customer data in Liquid:

Metafield strategy

Prior to April 2022, the app stored all custom data in a single metafield using a JSON string. Shopify recently released metafield definitions, so we’ve introduced a new way to store metafield data that is compatible with Shopify's new metafield types and definitions. With this new strategy, Customer Fields will save all custom data column values into their own separate metafields.

You can control the app's metafield strategy within the app admin by going to Settings > Metafields. There are two options to choose from:

Liquid output

With the power of Liquid, you can use customer metafields to access the custom data collected by Customer Fields. The most common way to use metafields in Liquid is when editing the code for a store's theme or email notification templates.

To access custom data on the storefront or in email notifications you'll need to use one of the following syntaxes. Notice there are two different syntaxes (one for each strategy):

Shopify admin-compatible

Syntax:

customer.metafields.customer_fields.DATA_COLUMN_KEY.value

Bundled JSON metafield

Syntax:

customer.metafields.customer_fields.data["DATA_COLUMN_KEY"]

❗ Note: For either syntax, you'll need to replace DATA_COLUMN_KEY with the actual data column key you wish to use. The syntaxes above are simply meant to act as examples.

Liquid-friendly data types

Since each data column in Customer Fields has its own specific data type, you can apply type-specific Liquid filters to format the data, or even scope out certain attributes for an object of data.

Below you'll find several different examples of how to display metafield data for a customer:

Specific examples

1) Display value for a custom text data column with the key of 'pet_name':

Your pet's name: {{ customer.metafields.customer_fields["pet_name"].value }}

<!-- Outputs:
Your pet's name: Franklin
-->

2) Display value for a custom date data column using a Liquid date filter to control the format:

Your Birthday: {{ customer.metafields.customer_fields["birthday"].value | date: "%b %d, %Y" }}

<!-- Outputs:
Your Birthday: February 6, 1945
-->

3) Display value for a custom list data column using a Liquid filter to convert the array into a comma-separated string:

Your Hobbies: {{ customer.metafields.customer_fields["hobbies"].value | join: ", " }}

<!-- Outputs:
Your Hobbies: Cycling, Hiking, Video Games
-->

4) Display value for a custom file data column using the URL attribute to embed an image:

Profile pic: <img src="{{ customer.metafields.customer_fields["profile_pic"].value.url }}" style="max-width: 150px;">

<!-- Outputs:
Profile pic: <image> (150px max width)
-->

PDF agreement: <a href="{{ customer.metafields.customer_fields["contract"].value.url }}" target="_blank">{{ customer.metafields.customer_fields["contract"].value.name }}</a>

<!-- Outputs:
PDF agreement: <filename> (hyperlink that opens file in a new tab)
-->

6) Display values for a custom group_list data column using a for-loop to output certain data attributes in the array of objects:

{% for pet in customer.metafields.customer_fields.pets.value %}
Pet name: {{ pet.name }}
Pet weight: {{ pet.weight }}
{% endfor %}

<!-- Outputs:
Pet name: Franklin
Pet weight: 30 lbs
Pet name: Winston
Pet weight: 2 lbs
--->

7) (Advanced) Display values for a custom group_list column using a variable, multiple filters, iteration, and some control flow logic:

{% assign pets = customer.metafields.customer_fields.pets.value %}
<h4>Your Pets ({{ pets | size }} total)</h4>
{% for pet in pets %}
<ul>
<li>{{ pet.name | capitalize }} ({{ pet.type | downcase }}), {{ pet.energy_level | downcase }}></li>
{% if pet.birthday != nil %}<li> Born: {{ pet.birthday | date: "%b %d, %Y" }}</li>{% endif %}
<br>
</ul>
{% endfor %}

<!-- Outputs:
Your Pets (2 total)

Franklin (dog), lazy
Born: October 10th, 2015

Winston (hamster), active
--->


Looking for more technical details? 🤓

Learn more about the app's metafields using our Developer Documentation.

Did this answer your question?