Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Is there a way to see if a customer has an active subscription through liquid?
Something like
{% if customer.active_subscription %}
etc.
Thanks,
Hi @avanor!
The customer object in Liquid does not have an attribute for 'active subscription', but you can certainly use the customer object to do things like checking if the customer has an account or if they have opted-in for marketing: https://shopify.dev/docs/themes/liquid/reference/objects/customer
From my understanding you'd need to loop through a customer's orders and check to see if any of the orders contain selling plan line items: https://shopify.dev/tutorials/storefront-ux-guidelines-for-subscriptions#order-details. I personally do not have much experience with Shopify's new subscription feature, so maybe someone else can chime in with more details...
Hopefully this helps!
{% if customer.accepts_marketing == true %}
Do something...
{% else %}
Do something else...
{% endif %}
Another way is to add tag to a customer when customer subscribe and then check this looping though tags... Something like:
{% assign is_subscription_customer = false %}
{% for tag in customer.tags %}
{% if tag == 'Active Subscriber' %}{% assign is_subscription_customer = true %}{% break %}{% endif %}
{% endfor %}
{% if is_subscription_customer %}
<!-- Code for subscriber -->
{% else %}
<!-- Code for normal customer -->
{% endif %}
I've used first method only, but I'm sure second one works to...
Hope this helps 🙂
Hi there,
thanks for the answers. @MarinaP your solution requires that your assigment works in every case, i am not so happy with this "hack". I am also struggling to get active subscriptions in liquid. Is there any way to achieve this with the new theme app extensions?
I want to assign a liquid variable the result fo the GraphQL Query :
query {
subscriptionContracts(first: 10) {
edges {
node {
id
createdAt
status
nextBillingDate
customer {
firstName
lastName
}
billingPolicy {
interval
intervalCount
}
}
}
}
}
User | RANK |
---|---|
32 | |
30 | |
19 | |
9 | |
9 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By