> For the complete documentation index, see [llms.txt](https://docs.intelligems.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.intelligems.io/developer-resources/javascript-api/price-object.md).

# Price Object

For advanced and custom price testing integrations.

## Overview

The price object reflects whichever group the visitor landed in. See [Pricing Experiences](/pricing-experiences/pricing-experiences-overview.md) for how those groups are built, and [Optimizing Your Price-Test Integration](/performance-optimization/optimizing-your-price-test-integration.md) 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**

```javascript
...
// 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:

```javascript
const itemMinPrice = window.igData?.price.getMinPriceByProductId(product.id);
const itemMaxPrice = window.igData?.price.getMaxPriceByProductId(product.id);
```

## 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**

```javascript
...
// 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
...
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.intelligems.io/developer-resources/javascript-api/price-object.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
