memberr 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{%- assign customer = customer.metafields.app--60169453569--memberr_v2 -%}_10{% if customer %}_10<p>{{ customer.FIELD_NAME }}</p>_10{% endif %}
Available Metafields
Key | Type | Access | Description |
---|---|---|---|
current_balance | Money | Public Read | Customer's current available balance. |
upcoming_balance | Money | Public Read | Customer's pending balance that will become available. |
customer_membership | JSON | Public Read | Customer's membership details including ID, membership type, and expiration. |
The customer membership metafield customer_membership
is a JSON object that stores membership-related data for customers:
Key | Type | Required | Description |
---|---|---|---|
id | string | ✓ | Unique identifier for the customer membership record. |
membership_id | string | ✓ | Reference to the associated membership definition. |
created_at | string | ✓ | ISO timestamp when the membership was created. |
updated_at | string | ✓ | ISO timestamp when the membership was last modified. |
expires_at | string | null | ISO timestamp when the membership expires. Null for lifetime memberships. |
Customer Balance
The customer balance metafields store information about a customer's current and upcoming Store Credit balance.
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 }}
Example Usage Customer Membership
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
Always check if the metafield exists before accessing:
_10{% if customer.metafields.app--60169453569--memberr_v2.customer_membership %}_10 <!-- Access membership data -->_10{% endif %}
Parse dates appropriately:
_10{{ membership.created_at | date: "%Y-%m-%d" }}
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 %}
Consider timezone handling when displaying dates:
_10{{ membership.expires_at | date: "%B %d, %Y %I:%M %p %Z" }}
Always use the money filter with .value for balance fields:
_10{{ customer.metafields.app--60169453569--memberr_v2.current_balance.value | money }}
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>