Objects

An introduction to global and scoped objects in the Subscription Manager and how to use them
View as Markdown

What Is an Object?

Every Subscription Manager template has access to objects. These objects represent the data stored in Ordergroove — for example, the customer’s upcoming orders, subscriptions, addresses, etc. You can find a full list of all available objects in the Object Reference.


Scoped Objects vs Global Objects

All objects listed in the Object Reference are global objects and can be referenced within any template file.

If you use {% set my_variable = "foo" %} syntax to create your own variable, that variable will be made available to all template code that comes after the declaration, including other included templates.

Using {% for item in items %} syntax creates the item variable and makes it available only within the loop, until the code reaches a matching {% endfor %} block.


What Can You Do With Objects?

Objects are a powerful concept that controls the layout and functionality of the Subscription Manager. You can leverage objects to customize existing functionality or add support for your own custom business rules. We have provided some hypothetical examples below to help you get started.

Please Note

Examples below are provided for demonstration purposes only. You may need to modify this code further to make it work with your specific configuration.


Sample: Improve Subscription Reactivation Rates

Let’s say you’re noticing that a specific product in your catalog has a high cancellation rate. One thing you can do is improve the reactivation rate for certain products by offering an additional promotion. You can utilize the product object to display additional messaging to customers, enticing them to reactivate their subscription to B6 Vitamins.

reactivate-subscription.liquid
1{% set product = product_by_id[subscription.product] %}
2{% if product.name == "B6 Vitamin" %}
3<h1>Reactivate {{ product.name }} today and receive an extra discount on recurring orders!</h1>
4{% endif %}

Sample: Hide and Show Controls

One of the most frequent customizations is hiding or showing controls based on certain criteria. For example, to prevent gaming discounts on lower-margin items, you could remove the customer’s ability to cancel their subscription via the Subscription Manager for items under a certain dollar amount, and prompt them to call in to cancel instead.

Compliance with Click-to-Cancel

The FTC’s Click-to-Cancel rule requires businesses to provide a simple and immediate way for consumers to cancel recurring subscriptions and stop charges.

Before hiding or disabling the cancellation option in the Subscription Manager, consult your legal counsel to ensure compliance. Doing so may violate FTC regulations.

cancel-subscription.liquid
1{% for order_item in order_items %}
2{% if order_item.total_price >= 10 %}
3 <a>{{ 'cancel_subscription_button' | t }}</a>
4{% else %}
5 <p>
6 We're sorry but you cannot cancel this subscription via our website.<br />
7 Please contact our support at 555-555-5555
8 </p>
9{% endif %}

Sample: Content and Styling Based on Website Locale

The Subscription Manager comes out of the box with text that automatically changes based on the website’s locale. However, you may want to show additional content or style your Subscription Manager differently depending on the user’s location. This can be achieved using the global locale key. In the example below, we force a button to appear red when the site is viewed with a locale targeting Chinese customers.

send-now.liquid
1<button class="btn btn-primary {{ "red" if locale == "zh-cn" }}" type="button">
2{{ 'shipment_send_now_button' | t }}
3</button>

All you need to do is add a CSS class red to your styles, and the button will appear red only for customers viewing your site with this locale.