Can liquid reveal a customer's active subscription status?

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

Something like

{% if customer.active_subscription %}

etc.

Thanks,

1 Like

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

{% else %}

{% endif %}

I’ve used first method only, but I’m sure second one works to…

Hope this helps :slightly_smiling_face:

1 Like

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