Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to identify if an Order has a Subscription Product?

How to identify if an Order has a Subscription Product?

mog
Shopify Partner
6 0 2

I have tried to install multiple subscription-based apps on our store and after placing subscription orders I can't seem to figure out a way on the Orders API if a line item is subscription-based or not.

 

Could someone please advise on how to identify if an order has a Subscription Product Line Item?

Replies 9 (9)

csam
Shopify Staff (Retired)
267 40 51

Hi @mog 

 

A subscription created order will show 

    "source_name": "subscription_contract"

but there is no line_item property to indicate subscription status. Hope this helps!

 

To learn more visit the Shopify Help Center or the Community Blog.

mog
Shopify Partner
6 0 2

Thanks, but I don't see this on the initial order. Only the subsequent orders that are placed by the subscription app contain the "source_name" set to "subscription_contract".

kskinaba
Shopify Partner
1 0 1

I have the exact same question. I'd like to know a way to identify if an order is the initial order of a subscription using the Order API.

Jonathan-HA
Shopify Partner
336 26 107

I'm wondering about the same thing as well, just had a customer of one of our apps ask about it.

 

I don't see any field at the line item level in the Order API data that would indicate whether a line item was purchased as a subscription or not.

Co-Founder / Developer at Highview Apps
Our Shopify Apps: EZ Exporter | EZ Inventory | EZ Importer | EZ Notify | EZ Fulfill

Michael_Gibbons
Shopify Partner
4 1 1

This is an old post but I will post a solution for any unfortunate soul who happens upon this issue.

 

The order create webhook payload does not have any information relating to the selling plans purchased, nor does the storefront api. What you need to do is get the admin gql order id and query the order line items server-side, those objects do have the corresponding selling plan.

Using the existence of those properties as a flag you can determine if the product was purchased as a subscription or one-time.

joshlee84
Shopify Partner
4 0 2

Can you provide more detail on which properties you used to determine the selling plan?

joshlee84
Shopify Partner
4 0 2

Actually, I think I got it:

query = '''
{
order(id: "gid://shopify/Order/''' + order_id + '''") {
lineItems(first: 10) {
edges {
node {
title
sellingPlan {
name
}
}
}
}
}
}
'''
kei178
Shopify Partner
2 0 0

It's also mentioned on this page: https://help.shopify.com/en/manual/checkout-settings/script-editor/scripts-subscriptions

 


When merchants sell subscription products, those product are assigned a selling plan (by the subscription app). When you write scripts, you can use the lineitem object .selling_plan_id to identify when a product is being bought as a subscription.

Line items for subscriptions have a selling plan ID, whereas line items for one-time purchases don't have a selling plan ID.


irzum
Shopify Partner
3 0 2

It's very late now, but just want to give another work around since we have ui extension now so what i did is, in cart extension am checking if any lineItem is having "sellingPlan" (i am using recharge for subscription, so for any other app there might be a different attribute in lineItem, not sure), based on this this attribute am updating a cart attribute so that when order creation webhook run's i get that attribute with it. This way we don't have to call any other api call.