Manage subscription products on storefronts
You can use the Storefront API to retrieve subscription products on a storefront. Subscription products can be accessed from the
This guide shows you how to use the Storefront API to retrieve information about selling plans, including price adjustments and selling plan allocations. It also shows how to create a cart with a subscription line item.
RequirementsAnchor link to section titled "Requirements"
- You've completed the Getting started with the Storefront API guide.
You're familiar with querying products and collections.
You've created products, variants, and selling plan groups in your store.
Your Headless channel or custom app has the
unauthenticated_read_selling_plansaccess scopes. Learn how to request permissions for Headless channels.
Step 1: Query selling plans for a productAnchor link to section titled "Step 1: Query selling plans for a product"
To retrieve information about selling plans, query a product by its handle (
sellingPlanGroups object associated with the product contains the individual selling plans, which include information such as delivery frequencies.
Individual selling plansAnchor link to section titled "Individual selling plans"
sellingPlans object, you can query the selling plan ID. This ID is used to identify which selling plan a customer has picked when they add a subscription product to their cart. You can also query whether purchasing the selling plan will result in multiple deliveries (
options field represents the selling plan options available in the drop-down list in the storefront.
The following example shows how to query a selling plan group associated with a product, and its individual selling plans. The
requiresSellingPlan field is
true, which means that the product can be purchased only as part of a selling plan.
Individual selling plans contribute their
options to the associated selling plan group. In the following example, a selling plan group has an option called
Delivery every. Each individual selling plan that belongs to the group contributes an option (
2 weeks, and
3 weeks) to the selling plan group.
Step 2: Query price adjustments on variantsAnchor link to section titled "Step 2: Query price adjustments on variants"
A product can have multiple variants and each variant can have up to two price adjustments. The
priceAdjustments field represents how a selling plan affects pricing when a variant is purchased with a selling plan.
If a variant has multiple price adjustments, then the first price adjustment applies when the variant is initially purchased. The second price adjustment applies after a certain number of orders (specified by the
orderCount field) are made.
If a selling plan doesn't have any price adjustments, then the unadjusted price of the variant is the effective price.
Price adjustment valuesAnchor link to section titled "Price adjustment values"
adjustmentValue field represents the type of price adjustment.
A variant can have the following types of price adjustment values:
SellingPlanPercentagePriceAdjustment: A percentage amount deducted from the original variant price when it's purchased with a selling plan. For example, 10% off.
SellingPlanFixedAmountPriceAdjustment: A specific amount deducted from the original variant price when it's purchased with a selling plan. For example, 10.00 USD off.
SellingPlanFixedPriceAdjustment: A fixed price adjustment for a variant that's purchased with a selling plan. For example, if the selling plan offers a 10% discount on a variant that's regularly priced at 60.00 USD, then the price is 54.00 USD (60.00 USD x 0.90).
The following example retrieves the price adjustment value types on a variant. The response shows a variant that has a 20% discount when it's purchased with a selling plan.
Step 3: Query selling plan allocations and variant pricesAnchor link to section titled "Step 3: Query selling plan allocations and variant prices"
A selling plan allocation describes the effect that each selling plan has on variants when they're purchased. It other words, it represents the combination of a variant and a selling plan.
Selling plan allocations contain the resulting prices for variants when they're purchased with a specific selling plan:
price: The price that's paid when the purchase is made. For example, for a prepaid plan for 6 deliveries of 10.00 USD granola, where the customer gets 20% off, the price is 6 x 10 USD x 0.80 = 48.00 USD.
compareAtPrice: The price of the variant when it's purchased without a selling plan for the same number of deliveries. For example, 6 deliveries x 10 USD granola = 60.00 USD.
perDeliveryPrice: The effective price for a single delivery. For example, for a prepaid plan for 6 deliveries, where the price is 48.00 USD, the per delivery price is 8.00 USD.
unitPrice: The unit price of the variant associated with the selling plan. For example, a merchant might sell a subscription product in quantities or measurements. If the variant has no unit price, then this field returns
Prices display in the customer's currency if the shop is configured for it. For example, if a customer in Canada tries to pay for a product on a storefront based in the United States, then prices display in CAD.
The following query shows how to retrieve information about a variant associated with a selling plan. The response shows the prices of the variant.
Without the selling plan, the variant price is 60.00 CAD (
compareAtPrice). If the variant is purchased with a selling plan that provides a 20% discount, then the
price is 48.00 CAD. The
perDeliveryPrice is determined the price (48.00 CAD) divided by the number of deliveries (6), which equals 8.00 CAD per delivery.
Step 4: Create a cart and a subscription line itemAnchor link to section titled "Step 4: Create a cart and a subscription line item"
You can use the
cartCreate mutation to create a cart that contains the purchase of a variant with a selling plan. In your input to the mutation, provide the line item quantity, variant ID, and selling plan ID.
In the following example, the response returns each cart line with the quantity, the variant (
merchandise) purchased, and the selling plan that's associated with the variant. The resulting prices for the variant when it's purchased with the selling plan are also returned.
- Learn how to create and update a cart in Shopify with the Storefront API.
- Learn how to query international prices for products and orders, and explicitly set the context of a cart and checkout.
- Learn how to manage customer accounts with the Storefront API.
- Retrieve metafields with the Storefront API to access additional information from different types of resources.
- Support multiple languages on a storefront with the Storefront API.