customer subscription in liquid

avanor
Visitor
2 0 2

Is there a way to see if a customer has an active subscription through liquid?

Something like 

{% if customer.active_subscription %}

etc.

 

Thanks,

Replies 3 (3)

Kyle_W
Shopify Expert
172 26 105

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!

Kyle W | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (300+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (200+ reviews)

MarinaP
Tourist
8 0 3

 

{% 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 🙂 

 

XamHans
Tourist
7 0 3

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
        }
      }
    }
  }
}