Home

Shopify Customer Metafields

memberr uses Shopify customer metafields to store customer-specific data such as membership information. These metafields are accessible through the Shopify Admin API and Storefront API.

Accessing Customer Metafields

To access customer metafields in your Liquid templates, use the following code:


_10
{{ customer.metafields.app--60169453569--memberr_v2.FIELD_NAME }}

Customer Balance

The customer balance metafields store information about a customer's current and upcoming Store Credit balance.

Current Balance


_10
{{ customer.metafields.app--60169453569--memberr_v2.current_balance }}

PropertyValue
Namespaceapp--60169453569--memberr_v2
Keycurrent_balance
TypeMoney
AccessPublic Read
DescriptionCustomer's current available Store Credit balance

Upcoming Balance


_10
{{ customer.metafields.app--60169453569--memberr_v2.upcoming_balance }}

PropertyValue
Namespaceapp--60169453569--memberr_v2
Keyupcoming_balance
TypeMoney
AccessPublic Read
DescriptionCustomer's pending Store Credit balance that will become available in the future

Example Usage

Here's how to display customer balance information in your Liquid templates:


_13
<div class="customer-balance">
_13
<h2>Your Store Credit</h2>
_13
_13
{% if customer.metafields.app--60169453569--memberr_v2.current_balance %}
_13
<p>Available Balance: {{ customer.metafields.app--60169453569--memberr_v2.current_balance.value | money }}</p>
_13
{% else %}
_13
<p>No available balance</p>
_13
{% endif %}
_13
_13
{% if customer.metafields.app--60169453569--memberr_v2.upcoming_balance %}
_13
<p>Pending Balance: {{ customer.metafields.app--60169453569--memberr_v2.upcoming_balance.value | money }}</p>
_13
{% endif %}
_13
</div>

Customer Membership

The customer membership metafield stores information about a customer's current membership status and details.

Accessing Customer Membership


_10
{{ customer.metafields.app--60169453569--memberr_v2.customer_membership }}

PropertyValue
Namespaceapp--60169453569--memberr_v2
Keycustomer_membership
TypeJSON
AccessPublic Read
DescriptionCustomer's membership information

JSON Structure

The customer membership data is stored as a JSON object with the following structure:


_10
{
_10
"id": "string",
_10
"membership_id": "string",
_10
"created_at": "string",
_10
"updated_at": "string",
_10
"expires_at": "string | null"
_10
}

FieldTypeRequiredDescription
idStringYesUnique identifier for the customer membership
membership_idStringYesIdentifier of the associated membership
created_atStringYesTimestamp of when the customer membership was created
updated_atStringYesTimestamp of when the customer membership was last updated
expires_atString or nullNoTimestamp of when the customer membership expires, or null if it does not expire

Example Usage

Here's how to access and display customer membership information in your Liquid templates:


_27
{% if customer.metafields.app--60169453569--memberr_v2.customer_membership %}
_27
{% assign customer_membership = customer.metafields.app--60169453569--memberr_v2.customer_membership %}
_27
{% assign membership_id = customer_membership.membership_id %}
_27
{% for membership in shop.metaobjects.app--60169453569--membership -%}
_27
{% if membership.id == membership_id and membership.is_active %}
_27
{% assign membership = membership %}
_27
{% endif %}
_27
{% endfor %}
_27
_27
{% if membership % }
_27
<h2>Your Membership</h2>
_27
<ul>
_27
<li>Membership ID: {{ customer_membership.membership_id }}</li>
_27
<li>Membership Name: {{ membership.name }}</li>
_27
<li>Start Date: {{ customer_membership.created_at | date: "%B %d, %Y" }}</li>
_27
{% if customer_membership.expires_at %}
_27
<li>Expires: {{ customer_membership.expires_at | date: "%B %d, %Y" }}</li>
_27
{% else %}
_27
<li>Never expires</li>
_27
{% endif %}
_27
</ul>
_27
{% else %}
_27
<p>No active membership</p>
_27
{% endif %}
_27
{% else %}
_27
<p>No active membership</p>
_27
{% endif %}

Access Levels

The customer metafields have different access levels depending on the context:

  • Public Read: Accessible in both Admin and Storefront APIs
  • Customer Account Read: Accessible in the customer account section
  • None: Not accessible

Best Practices

  1. Always check if the metafield exists before accessing:

_10
{% if customer.metafields.app--60169453569--memberr_v2.customer_membership %}
_10
<!-- Access membership data -->
_10
{% endif %}

  1. Parse dates appropriately:

_10
{{ membership.created_at | date: "%Y-%m-%d" }}

  1. Handle null values for optional fields:

_10
{% if membership.expires_at %}
_10
{{ membership.expires_at | date: "%Y-%m-%d" }}
_10
{% else %}
_10
Permanent membership
_10
{% endif %}

  1. Consider timezone handling when displaying dates:

_10
{{ membership.expires_at | date: "%B %d, %Y %I:%M %p %Z" }}

  1. Always use the money filter with .value for balance fields:

_10
{{ customer.metafields.app--60169453569--memberr_v2.current_balance.value | money }}

  1. Consider showing both current and upcoming balances together for better user experience:

_10
{% assign current = customer.metafields.app--60169453569--memberr_v2.current_balance.value | default: 0 %}
_10
{% assign upcoming = customer.metafields.app--60169453569--memberr_v2.upcoming_balance.value | default: 0 %}
_10
{% assign total = current | plus: upcoming %}
_10
_10
<div class="balance-summary">
_10
<p>Available now: {{ current | money }}</p>
_10
<p>Coming soon: {{ upcoming | money }}</p>
_10
<p>Total: {{ total | money }}</p>
_10
</div>