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 }}
Property | Value |
---|---|
Namespace | app--60169453569--memberr_v2 |
Key | current_balance |
Type | Money |
Access | Public Read |
Description | Customer's current available Store Credit balance |
Upcoming Balance
_10{{ customer.metafields.app--60169453569--memberr_v2.upcoming_balance }}
Property | Value |
---|---|
Namespace | app--60169453569--memberr_v2 |
Key | upcoming_balance |
Type | Money |
Access | Public Read |
Description | Customer'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 }}
Property | Value |
---|---|
Namespace | app--60169453569--memberr_v2 |
Key | customer_membership |
Type | JSON |
Access | Public Read |
Description | Customer'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}
Field | Type | Required | Description |
---|---|---|---|
id | String | Yes | Unique identifier for the customer membership |
membership_id | String | Yes | Identifier of the associated membership |
created_at | String | Yes | Timestamp of when the customer membership was created |
updated_at | String | Yes | Timestamp of when the customer membership was last updated |
expires_at | String or null | No | Timestamp 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
- 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>