Liquid, JavaScript, themes, sales channels
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
}
}
}
}
}
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024