Price Object
For advanced and custom price testing integrations.
Overview
The price object reflects whichever group the visitor landed in. See Pricing Experiences for how those groups are built, and Optimizing Your Price-Test Integration if you're reading prices on a latency-sensitive path.
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 by Variant ID
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 Price by Product ID
You may not have a specific variant ID, in which case you intend to look up the price for a product. Since different variants on the product may contain different prices, you must specify if you want the minimum or maximum price for a given product id. For example:
Get Compare Price by Variant ID
To get the compare price for a product, you can use window.igData?.price.getComparePriceByVariantId(). This will return the compare 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.
Get Discount by Variant ID
To get the discount amount applied by a price test, use window.igData?.price.getDiscountByVariantId().
If there is no price test running or this product is not in a price test, we will return null.
Get Alternate Variant ID
To get the alternate variant id used by a price test, use window.igData?.price.getAltVariantId().
If there is no price test running or this product is not in a price test, we will return null.
Get Alternate Product Handle
To get the alternate product handle used by a price test, use window.igData?.price.getAltProductHandle().
If there is no price test running or this product is not in a price test, we will return null.
Get Product ID From Handle
To get a product id from a product handle, use window.igData?.price.getProductIdFromHandle().
If the product handle is not found, we will return null.
Get Product by ID
To get product data from the price test configuration, use window.igData?.price.getProduct().
If the product is not found in the price test configuration, we will return null.
Update Quantity Buttons
To update Quantity Buttons widgets across the page, use window.igData?.price.updateQuantity().
This is only effective when the Quantity Buttons widget is installed.
Get Total Savings
To get total cart savings from price tests, use window.igData?.price.getTotalSavings().
Returns a number in shop currency.
Get Total Cart Cost
To get total cart cost (after price test changes), use window.igData?.price.getTotalCartCost().
Returns a number in shop currency.
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
Last updated
Was this helpful?