Add a Subscription to Cart
Use og-offer components and CSS variables to build a custom subscription enrollment UI
Each product is tied to a subscription offer which details the different subscription frequencies and discounts that may be applied, amongst other things. Using our components it is possible to retrieve these offers and build your own customized subscription interface.
Defining the og-offer Element
We provide a way to customize how offer information is displayed on the page. The following code will present the default offer for the given product ID:
Closing Tags
Custom elements cannot be self-closing because HTML only allows a few elements to be self-closing. Always write a closing tag (</og-offer>).
Alternatively, you can set the product ID using JavaScript:
Location
The location attribute allows different offers to display in different locations (e.g. PDP vs. Cart). The value can be any string.
Note: development work will be required to add the location attribute to the element (i.e. location="X").
Recommended location naming conventions:
PDP— Product Detail Page offerCart— Shopping Cart offerOrder Review— Order Review offerConfirmation— Confirmation page offer
Main.js
Ordergroove’s main.js must be tagged on every page where an <og-offer> element lives. It loads your offer content and styling. The script should only be tagged once per page and can render multiple offers on the same page.
The script URL is made up of two parts: the frontend static domain and your Merchant ID. Use the correct domain for your environment:
- Staging:
https://staging.static.ordergroove.com - Production:
https://static.ordergroove.com
If you need your Merchant ID, please reach out to support.
Writing Custom Offer Content
The <og-offer> element provides 2 slots that can be populated with custom content:
slot="standard-template"slot="iu-template"
standard-template
Use this slot to place content when a standard offer is presented to the user:
From here you can start creating your custom offer experience using Ordergroove offer web components.
Offer Context
Most web components such as og-optin-button or og-optin-status require a product attribute. However, when these components are wrapped inside an <og-offer> element using its slots, they will inherit the product ID from the parent <og-offer> if their own product attribute is not specified:
CSS Properties and Scope
A feature of web components and the shadow DOM specification is that styles are scoped — you can’t directly modify most CSS rules within our components. Learn more about shadow DOM.
We have exposed the following CSS custom properties (variables) for styling:
Here is a sample variable declaration:
Ordergroove sets these variables at the global scope through our UI:
You can override them for specific sections by defining your own values, which will take precedence over the global ones set by Ordergroove: