Add a subscription widget to Shopify product details page
This guide will help you to add a widget for managing the product subscription on product details page of your Shopify store.
Last updated
This guide will help you to add a widget for managing the product subscription on product details page of your Shopify store.
Last updated
The widget will allow your customers to manage their subscription for the product they are viewing. They can add the product to their subscription or update the quantity of the product in their subscription.
If you have more than one product variant, the selected variant will be added to the subscription. If the customer has an active subscription for the product, it will show the current quantity of the product in the subscription.
You can customize the widget content and style by updating the configuration options in the widget code.
Before you start, you need to have the following:
Connect your Shopify store to Firmhouse. If you haven't connected your Shopify store to Firmhouse yet, you can follow the instructions in this article to connect your store to Firmhouse.
Install the Firmhouse Shopify SSO app on your Shopify store. You can follow the instructions in this article to install the app.
To add the widget to your Shopify store, you need to add the following JavaScript code to your theme. You can add the following code to the theme.liquid
file in the Layout directory of your theme. You can add the code just before the closing </head>
tag.
We're using the customer
object to check if the user is logged in. That way, we only load the widget script if the user is logged in.
After adding the code, it will look like this:
To add the widget to your product details page, you can update the main-product.liquid
file in the Sections directory of your theme.
A good place to add the widget is just on top of the product info section. This could vary from theme to theme but you can search for <section
and add the following code as the first child of the section:
This div
is a placeholder, and when the page is loaded it will get replaced with the actual iframe. After adding the code, it will look like this:
You can now save the file and refresh the product details page to see the widget in action.
You can customize the widget by updating the configuration options in the widget code. Here are the available configuration options:
data-primary-color
: The primary color of the widget. You can use any valid CSS color value.
data-secondary-color
: The secondary color of the widget. You can use any valid CSS color value.
If you would like to update the text content of the widget, you can update the following variables in the widget code:
data-copy-add-to-subscription
: The text for the "Add to subscription" button.
data-copy-add-to-subscription-copy
: The text for "Do you want to add this product to your subscription?"
If you would like to customize the content with HTML, you can update the following variables in the widget code:
data-template-add-to-subscription-body
: ID of the template for the "Add to subscription" body content.