Price Object

For advanced and custom price testing integrations.

Overview

If your Shopify theme has a lot of custom javascript, you will likely need to use this API to make price tests work. Common use cases for custom javascript are things like:

  • Custom bundle and pack builders

  • Custom upsells for an item

  • Custom in-cart upsells

  • PDPs with lots of customization that don't use a typical <form type="/cart/add">

Get Price

To get the price for a product, you can use window.igData?.price.getPriceByVariantId(). This will return the price as a string in currency (i.e. "29.95")

If there is no price test running or this product is not in a price test, we will return null.

Example

...
// Imagine item = product.variant;
// You want the price for that item
const itemPrice = window.igData?.price.getPriceByVariantId(item.id) || item.price;
...

Get Subscription Discount

To get the price for a product, you can use window.igData?.price.getSubscriptionDiscountByVariantId(). This will return the discount object: {subscriptionDiscount: 10, subscriptionDiscountType: "percentage"}

The types for subscription discount are: "percentage" | "dollar"

Example

...
// Imagine item = product.variant;
// You want the subscription discount for that item
const igSubDisc = window.igData?.price.getSubscriptionDiscountByVariantId(item.id);
console.log("Discount:", igSubDisc?.subscriptionDiscount)
// Discount: 10
...

Last updated