Getting Smartrr on your site, from Shopify to headless themes.
Implementing Smartrr on headless storefronts using the Shopify Plus API
Last updated: April 3, 2024
Note: before implementing Smartrr, it's important to review Shopify's subscription requirements to determine your eligibility for offering subscriptions on your storefront. You must also have inventory tracking enabled for a product to be subscription-eligible.
As of 2023, Shopify has begun offering New customer accounts as a setting option. New customer accounts are not compatible with apps; please ensure you are using Classic customer accounts with Smartrr in order to display our Modern Account Portal where your customers will be able to access and manage their subscriptions.
From the Shopify app store, install the Smartrr app.
In your Shopify admin ([your-store-name].myshopify.com), navigate to 'Apps'. The Smartrr app should now show on your app list.
Click on the Smartrr app to open. Navigate to the Integrations tab in the left-hand navigation and generate a new API token using the button that reads Add Key.
We recommend setting both your Token Nickname and your Application Name as the name of the platform you are authorizing for. We also recommend that Application Name specifically be in all capital letters, without spaces.
Important: Ensure that token's permissions for Selling Plan are left set at the default selection: Selling Plan: Read. If permissions are toggled to "None" you will not be able to read Selling Plans from the API.
Use the below endpoint to call for information about product Subscription Programs.
Using Shopify’s Storefront API, product’s selling plan groups can be pulled. To get only Smartrr selling plan groups, filter by appName and limit to Smartrr. Selling plans can be accessed from the selling plan groups.
To retrieve selling plans using Shopify's Storefront API, you can use a GraphQL query. Below is an example of how you might construct a query to fetch selling plans and their details based on a selling plan group:
Shopify selling plan group documentation: https://shopify.dev/docs/api/storefront/2024-10/objects/SellingPlanGroup#top
Shopify product documentation:
https://shopify.dev/docs/api/storefront/2024-10/queries/product
Subscription Programs are configured in the Subscription Programs tab in the left hand navigation of the Smartrr app.
cache
true/false
Available values : true, false
From the call response, use the data provided in the sellingPlans[ ] array to power the storefront display. Submit the shopifyNumericId value for the field selling_plan in the form POST submission in order to attach a Subscription Group alongside an item added to a customer’s cart.
Be sure to replace <shopify domain> with your store's shopify domain. Note, this is required to be a part of cart workflow and not checkout workflow as Shopify does not support subscriptions within the checkout workflow.
For more information on this POST method, visit Shopify's documentation on Cart API References.
The selling_plan property NEEDS to be provided for any subscription line item that is added to cart. Use the cartLinesAdd mutation from Shopify Storefront API to do this.
Shopify cartlinesAdd documentation: https://shopify.dev/docs/api/storefront/2024-10/mutations/cartLinesAdd#argument-lines
200: OK JSON object of the line items associated with the added items422: Unprocessable Entity Occurs when the exact quantity specified for one of the items can't be added to the cart
Important: The product/variant will need to be enabled for the respective Subscription Program in the Smartrr admin portal. These can be detected with the productIds[ ] and/or variantIds[ ] array.
There are three methods for brands to display the Smartrr's Shopify liquid account portal on a headless shop.
We still recommend completing Smartrr's in-app Setup instructions up to step 3. Smartrr Installation – part 1. Install Snippets onto a dummy theme for developers to see how Smartrr renders the account portal, or if your developers would like to duplicate a piece of liquid functionality to headless.
[Recommended] Forward /account –related URLs to your {your-store}.myshopify.com domain.
This is our recommended method as it allows Shopify to continue handling all account actions (Login/Logout/Register/Checkout).
Create an account page on your site using the code found in your Shopify theme customers/account.liquid and use <iframe> to display it. This works for headless shops using React.
Duplicate smartrr-account.liquid in HTML, replacing the liquid code with the corresponding HTML Code. This works for headless shops not using React.
For methods 2 and 3, please follow these additional instructions:
The /customer/auth/session endpoint expects a liquidCustomer object. If the myshopify.com/account page is not used, the data may need to be pulled elsewhere. The customer data can be retrieved from Shopify Storefront API.
Below is the schema for the object.
How to add Smartrr to collection pages, landing pages, and custom snippet blocks within Shopify.
Smartrr can be added to any collection page where a product form is present.
Add the {% render 'smartrr-product', product: product, smartrr_unique_id: product.id, smartrr_collection: true %}
snippet to the desired product form.
Ensure smartrr_unique_id
value is the product ID.
Add the {% render 'smartrr-product-styles %}
tag to the top of the collection page file.
Add the <script type="text/javascript" src="{{ 'smartrr-product-script.js' | asset_url }}"></script>
script tag to the collection page. Make sure this is placed before the {% render 'smartrr-product' %}
tag is rendered.
Smartrr can be added to any landing page where a product form is present AND you are able to manually pull in the liquid product object.
One method of getting the liquid product object is by using the all products
objects and assigning the product handle.
Example:
{% assign product = all_products['product-handle'] %}
For more information, .
Add the {% render 'smartrr-product' %}
snippet to the desired product form alongside the smartrr_unique_id: product.id %
attribute.
Ensure smartrr_unique_id
value is the product ID.
Example:
Example:
Implementing Smartrr on storefronts with one of Shopify’s 2.0 free themes: Dawn, Craft, Crave, and Sense.
Last updated: April 3, 2024
Note: Before implementing Smartrr, it's important to to determine your eligibility for offering subscriptions on your storefront. You must also have enabled for a product to be subscription-eligible.
If your store is using , and have not , you’re eligible for our simple one-click automated install of Smartrr via our in-app Setup page.
As of 2023, Shopify has begun offering New customer accounts as a setting option. New customer accounts are not compatible with apps; please ensure you are using Classic customer accounts with Smartrr in order to display our Modern Account Portal where your customers will be able to access and manage their subscriptions.
Within the Smartrr app navigate to Setup under RESOURCES in the left-hand menu.
Subscription Programs are the heart of the Smartrr app. If you're just getting started with subscriptions, we can create a demo program for you by clicking Use a demo program. This will automatically create a "Subscribe & Save 10%" program for your shop.
Now that your Subscription Program is created, your next step is to assign a product/s to this program.
Similarly to above, Smartrr can create a demo product for you if you press Use a demo product. This will create a Smartrr Snack Cookie (Demo) in your Shopify shop. You can use this demo product for previewing purposes, and will be able to delete it at a later date directly within your Shopify admin.
Note: If you select to create a Demo Product, it won't appear in previews or in your storefront until you go to your Shopify admin and set the product sales channel availability to "Online Store".
If you want to start with one of the existing products in your shop, press Select from existing products. You can select one or multiple products from the modal that appears.
Now that you've completed the required Subscription setup steps, explore the remaining cards on this tab for ways you can further optimize your subscription business:
Customize the look and feel of your customer account portal
Warning: To prevent Smartrr from showing up on your site before you're ready to launch, we recommend navigating back to Shopify’s Themes to duplicate a copy of your current theme (Actions > Duplicate). Name it something that is easily recognizable, such as [Your Store] Smartrr Integration Copy [Date].
Select the Shopify theme you'd like Smartrr snippets to be in stalled on. Smartrr Snippets are files that are injected into your code base and will not modify any existing liquid files. These are required in order to render Smartrr on your storefront. There are five files that will be added under the Snippets section in your theme's liquid code.
Smartrr's subscription widget is an app block that can be added to your Default product page from your Shopify theme's online customizer.
If you installed Smartrr snippets to a theme that supports our widget, you will see a green banner during this step that reads: "You're using a Shopify theme that supports the block for our Smartrr Subscription widget."
Below are Shopify themes that are compatible with Smartrr's subscription widget: Colorblock Craft Crave Creator Dawn Enterprise Expanse Fetch Focal Impact Impulse Motion Origin Prestige Publisher Refresh Ride Sense Spotlight Streamline Studio Taste Warehouse
Click Add Smartrr subscription widget to be taken to your live theme editor. Make sure you are viewing Products > Default product. Additionally, make sure you are previewing a product that you have added to a Smartrr subscription program. Under Product information, click Add block and find Subscription Options.
You can customize the look and feel of Smartrr Subscription Options on your by manipulating the block's settings in the left-hand sidebar.
Note: 💻 Have a developer who would like to make even more changes to Smartrr's Widget? They can add custom CSS in the "Custom CSS" block.
Whether you've created a demo Subscription Program or made a new program from scratch, you may need to double check and make sure your program details have been successfully "saved". To do this, go to Subscription Programs > Manage Program. Check and see if there is a Discard / Save banner at the top, and click the green Save button.
To add Smartrr's pricing element outside of the subscription widget, you can add the following code:
Styling can be changed by adding the following values to the data-smartrr-price-style
attribute.
original
(Adds the original variant price/one-time purchase)
original-compare
(Adds the original variant price/one-time purchase price and the compare price)
overwrite
(Adds the current selected subscription plan's price)
overwrite-compare
(Adds the current selected subscription plan's price and compare price)
strike
(Discounted price struck through)
strike-compare
(Compare at price struck through)
Find the product liquid file in your theme's code. This is usually named product.liquid
or main-product.liquid
, but can also be uniquely named if your shop uses a custom theme. If you can't find this file, you can also use theme.liquid
.
At the bottom of the file, paste the following code:
In lines 4-5 above, input the unique selector for your variant selector elements. This can be done by inspecting the elements using your browser's developer tools and finding a class or data-attribute that is used only for variant selectors. Examples below:
Note: If your variant selectors are not <input>
elements, then you can change the 'change'
event listener to 'click'
.
Implementing Smartrr on storefronts with modified Shopify themes or custom liquid themes
Last updated: April 3, 2024
Coming from our app? to skip directly to guided install instructions.
Note: Before implementing Smartrr, it's important to to determine your eligibility for offering subscriptions on your storefront. You must also have enabled for a product to be subscription-eligible.
As of 2023, Shopify has begun offering New customer accounts as a setting option. New customer accounts are not compatible with apps; please ensure you are using Classic customer accounts with Smartrr in order to display our Modern Account Portal where your customers will be able to access and manage their subscriptions.
Within the Smartrr app navigate to Setup under RESOURCES in the left-hand menu.
Subscription Programs are the heart of the Smartrr app. If you're just getting started with subscriptions, we can create a demo program for you by clicking Use a demo program. This will automatically create a "Subscribe & Save 10%" program for your shop.
Now that your Subscription Program is created, your next step is to assign a product/s to this program.
Similarly to above, Smartrr can create a demo product for you if you press Use a demo product. This will create a Smartrr Snack Cookie (Demo) in your Shopify shop. You can use this demo product for previewing purposes, and will be able to delete it at a later date directly within your Shopify admin.
Note: If you select to create a Demo Product, it won't appear in previews or in your storefront until you go to your Shopify admin and set the product sales channel availability to "Online Store".
If you want to start with one of the existing products in your shop, press Select from existing products. You can select one or multiple products from the modal that appears.
Now that you've completed the required Subscription setup steps, explore the remaining cards on this tab for ways you can further optimize your subscription business:
Customize the look and feel of your customer account portal
Warning: To prevent Smartrr from showing up on your site before you're ready to launch, we recommend navigating back to Shopify’s Themes to duplicate a copy of your current theme (Actions > Duplicate). Name it something that is easily recognizable, such as [Your Store] Smartrr Integration Copy [Date] so that when you modify the below code, you know you are updating the correct theme.
Select the Shopify theme you'd like Smartrr snippets to be in stalled on. Smartrr Snippets are files that are injected into your code base and will not modify any existing liquid files. These are required in order to render Smartrr on your storefront. There are five files that will be added under the Snippets section in your theme's liquid code.
Smartrr's subscription widget is an app block that can be added to your Default product page from your Shopify theme's online customizer. However, if you're not using a liquid Shopify theme compatible with app blocks, and/or are planning to manually render subscription options on your shop's PDPs with the assistance of a developer, you'll need to use our guided install process.
In your duplicated theme’s liquid code files, find the liquid file where your site’s product form information is being stored. This is usually called main-product.liquid or product.liquid. This file is typically located under either the Sections (for Online Store 2.0) or Templates (for older Shopify themes) heading.
Once you’ve opened the file, search for the product form {%- form 'product'}, paste the following Smartrr snippet inside the form. We typically recommend placing between the variant selector and the quantity selector, but you can place in any order you see fit.
When added, the product form should look something like this:
In your duplicated theme’s code base, find the liquid file for your store’s account page. This is usually called customers/account.liquid. This file is typically located under either the Templates heading.
At the very beginning of the file, paste the following snippet:
The file should look like this:
Save the file.
Whether you've created a demo Subscription Program or made a new program from scratch, you may need to double check and make sure your program details have been successfully "saved". To do this, go to Subscription Programs > Manage Program. Check and see if there is a Discard / Save banner at the top, and click the green Save button.
Lastly, you can use custom liquid to pull in selling plan groups (a.k.a. subscription programs) and their selling plans (a.k.a. subscription plans). With this, you can loop through the selling plans to build a UI where selling plans can be selected. For more information on selling plan groups,
Make sure that the selling plan ID is being captured upon adding product to the cart. The selling_plan property is needed for the POST request to the cart API. For more information, .
Alternatively, you can create a new program from scratch by pressing Create my own program. You'll be redirected to our Subscription Program tab to complete this step.
Note: We recommend always using for your Shopify products when offering subscriptions, even if there is only one option for your product. Shopify auto-assigns a "Default variant" to a product that does not have any variants associated with it. If you decide to add variants to a product at a later date, and subscriptions are already running with the "Default variant", then those subscriptions will fail and will need to be re-mapped.
Note: If you're planning on using , leave the I'm planning on using Smartrr's subscription widget box checked. If you're not using a liquid Shopify theme compatible with app blocks, and/or are planning to manually render subscription options on your shop's PDPs with the assistance of a developer, uncheck this box. If you're unsure, no worries. You can always duplicate a clean version of your Shopify theme and re-install Smartrr snippets again.
Don't see this banner?
Still having trouble installing and don’t have access to a developer? We partner with a handful of excellent agencies. We also offer full white-glove onboarding support with our
If your store is using , and have not , you’re eligible for our simple one-click automated install of Smartrr via our in-app Setup page.
Alternatively, you can create a new program from scratch by pressing Create my own program. You'll be redirected to our Subscription Program tab to complete this step.
Note: We recommend always using for your Shopify products when offering subscriptions, even if there is only one option for your product. Shopify auto-assigns a "Default variant" to a product that does not have any variants associated with it. If you decide to add variants to a product at a later date, and subscriptions are already running with the "Default variant", then those subscriptions will fail and will need to be re-mapped.
Note: If you're planning on using , leave the I'm planning on using Smartrr's subscription widget box checked. If you're not using a liquid Shopify theme compatible with app blocks, and/or are planning to manually render subscription options on your shop's PDPs with the assistance of a developer, uncheck this box. If you're unsure, no worries. You can always duplicate a clean version of your Shopify theme and re-install Smartrr snippets again.
Save the file. You should be able to preview Smartrr on your site upon successfully modifying this product form. Having trouble? Skip to steps.
If you would like to display a link to your customer’s Account Portal from the order status page, please email us at and we will assist you.
Still having trouble installing and don’t have access to a developer? We partner with a handful of excellent agencies. We also offer full white-glove onboarding support with our