Anchor to Cart Transform Function APICart Transform Function API
A cart represents the merchandise that a customer intends to purchase, and the estimated cost associated with the cart. Transforming a cart refers to changing the pricing and presentation of items in a cart. To modify the appearance of cart items, such as updating titles and images, changing prices, and bundling items, you can only use the Cart Transform API.
Shopify Functions enable you to customize Shopify's backend logic. The Cart Transform API integrates this logic into the checkout flow.
Use the API to add product bundles to a store or break down bundled products into individual components, with associated data such as buyer identity, quantity, cost, and subscription information.
You can install a maximum of one Cart Transform Function on each store.
Anchor to Use casesUse cases
- Expand a cart line item to display the bundled items it contains.
- Merge multiple cart lines into a single line that represents a bundle.
- Update the presentation of line items in a cart to override their price, title, or image.
Only development stores or stores on a Shopify Plus plan can use apps with update
operations.
Anchor to Getting startedGetting started
Scaffolding the Function using Shopify CLI will automatically configure your TOML file. You can alter the default configuration to customize the way your Function operates.
Anchor to TargetsTargets
A target is an identifier in shopify.extension.toml
that specifies where you're injecting code into Shopify Function
APIs, or other parts of the Shopify platform. Each target is composed of three to four namespaces. The name begins with
a broad Shopify context and ends with the behavior of the extensible element.
Anchor to Run targetRun target
purchase.cart-transform.run
The run target modifies the pricing and presentation of items in a cart either using Shopify data or hardcoded values. The target returns a list of operations to be applied to cart line items.
For example, you might use this to automatically add a warranty when a specific product is added to a cart.
- Anchor to InputInputOBJECT
The
Input
object is the complete GraphQL schema that your Function can query as input to customize the presentation of items in a cart. Your Function receives only the fields that you request in the input query. To optimize performance, we highly recommend that you request only the fields that your Function requires.- Anchor to cartcart•Cart!non-null
The cart where the Function is running. A cart contains the merchandise that a customer intends to purchase and information about the customer, such as the customer's email address and phone number.
- Anchor to attributeattribute•Attribute
The custom attributes associated with a cart to store additional information. Cart attributes allow you to collect specific information from customers on the Cart page, such as order notes, gift wrapping requests, or custom product details. Attributes are stored as key-value pairs.
- •String
The key of the cart attribute to retrieve. For example,
.
Arguments
- •String!non-null
The key or name of the attribute. For example,
.
- Anchor to valuevalue•String
The value of the attribute. For example,
"true"
.
Fields
- •
- Anchor to buyerIdentitybuyer•
Identity BuyerIdentity Information about the customer that's interacting with the cart. It includes details such as the customer's email and phone number, and the total amount of money the customer has spent in the store. This information helps personalize the checkout experience and ensures that accurate pricing and delivery options are displayed to customers.
- Anchor to customercustomer•Customer
The customer that's interacting with the cart. A customer is a buyer who has an account with the store.
- Anchor to amountSpentamount•
Spent MoneyV2! non-null The total amount that the customer has spent on orders. The amount is converted from the shop's currency to the currency of the cart using a market rate.
- Anchor to amountamount•Decimal!non-null
A monetary value in decimal format, allowing for precise representation of cents or fractional currency. For example, 12.99.
- Anchor to currencyCodecurrency•
Code CurrencyCode! non-null The three-letter currency code that represents a world currency used in a store. Currency codes include standard standard ISO 4217 codes, legacy codes, and non-standard codes. For example, USD.
AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BDT, BGN, BHD, BIF, BMD, BND, BOB, BRL, BSD, BTN, BWP, BYN, BZD, CAD, CDF, CHF, CLP, CNY, COP, CRC, CVE, CZK, DJF, DKK, DOP, DZD, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JEP, JMD, JOD, JPY, KES, KGS, KHR, KID, KMF, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LTL, LVL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRU, MUR, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR, RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK, SGD, SHP, SLL, SOS, SRD, SSP, STN, SYP, SZL, THB, TJS, TMT, TND, TOP, TRY, TTD, TWD, TZS, UAH, UGX, USD, UYU, UZS, VED, VES, VND, VUV, WST, XAF, XCD, XOF, XPF, XXX, YER, ZAR, ZMW, BYR, STD, VEF
- Anchor to displayNamedisplay•
Name String!non-null The full name of the customer, based on the values for
and
. If
and
aren't specified, then the value is the customer's email address. If the email address isn't specified, then the value is the customer's phone number.
- Anchor to emailemail•String
The customer's email address.
- Anchor to firstNamefirst•
Name String The customer's first name.
- Anchor to hasAnyTaghas•
Any Tag Boolean!non-null Whether the customer is associated with any of the specified tags. The customer must have at least one tag from the list to return
true
.- Anchor to hasTagshas•
Tags [HasTag Response!]! non-null Whether the customer is associated with the specified tags. The customer must have all of the tags in the list to return
true
.- •[String!]!required
A comma-separated list of searchable keywords that are associated with the customer. For example,
returns customers with both the
and
Gold
tags.
Arguments
- Anchor to hasTaghas•
Tag Boolean!non-null Whether the Shopify resource has the tag.
- •String!non-null
A searchable keyword that's associated with a Shopify resource, such as a product or customer. For example, a merchant might apply the
sports
andsummer
tags to products that are associated with sportswear for summer.
Fields
- •
- •ID!non-null
A globally-unique ID for the customer.
- Anchor to lastNamelast•
Name String The customer's last name.
- Anchor to metafieldmetafield•Metafield
A custom field that stores additional information about a Shopify resource, such as products, orders, and many more. Using metafields with Shopify Functions enables you to customize the checkout experience.
- Anchor to namespacenamespace•String
A category that organizes a group of metafields. Namespaces are used to prevent naming conflicts between different apps or different parts of the same app. If omitted, then the app-reserved namespace is used.
- •String!required
The unique identifier for the metafield within its namespace. A metafield is composed of a namespace and a key, in the format
namespace.key
.
Arguments
- Anchor to jsonValuejson•
Value JSON!non-null The data that's stored in the metafield, using JSON format.
- Anchor to typetype•String!non-null
The type of data that the metafield stores in the
value
field.- Anchor to valuevalue•String!non-null
The data that's stored in the metafield. The data is always stored as a string, regardless of the metafield's type.
Fields
- Anchor to numberOfOrdersnumber•
Of Orders Int!non-null The total number of orders that the customer has made at the store.
- Anchor to emailemail•String
The email address of the customer that's interacting with the cart.
- Anchor to isAuthenticatedis•
Authenticated Boolean!non-null Whether the customer is authenticated through their customer account. If the customer is authenticated, then the
customer
field returns the customer's information. If the customer isn't authenticated, then thecustomer
field returnsnull
.- Anchor to phonephone•String
The phone number of the customer that's interacting with the cart.
- Anchor to purchasingCompanypurchasing•
Company PurchasingCompany The company of a B2B customer that's interacting with the cart. Used to manage and track purchases made by businesses rather than individual customers.
- Anchor to companycompany•Company!non-null
The company associated to the order or draft order.
- Anchor to createdAtcreated•
At DateTime! non-null The date and time (ISO 8601 format) at which the company was created in Shopify.
- Anchor to externalIdexternal•
Id String A unique externally-supplied ID for the company.
- •ID!non-null
The ID of the company.
- Anchor to metafieldmetafield•Metafield
A custom field that stores additional information about a Shopify resource, such as products, orders, and many more. Using metafields with Shopify Functions enables you to customize the checkout experience.
- Anchor to namespacenamespace•String
A category that organizes a group of metafields. Namespaces are used to prevent naming conflicts between different apps or different parts of the same app. If omitted, then the app-reserved namespace is used.
- •String!required
The unique identifier for the metafield within its namespace. A metafield is composed of a namespace and a key, in the format
namespace.key
.
Arguments
- Anchor to jsonValuejson•
Value JSON!non-null The data that's stored in the metafield, using JSON format.
- Anchor to typetype•String!non-null
The type of data that the metafield stores in the
value
field.- Anchor to valuevalue•String!non-null
The data that's stored in the metafield. The data is always stored as a string, regardless of the metafield's type.
Fields
- Anchor to namename•String!non-null
The name of the company.
- Anchor to updatedAtupdated•
At DateTime! non-null The date and time (ISO 8601 format) at which the company was last modified.
- Anchor to contactcontact•Company
Contact The company contact associated to the order or draft order.
- Anchor to createdAtcreated•
At DateTime! non-null The date and time (ISO 8601 format) at which the company contact was created in Shopify.
- •ID!non-null
The ID of the company.
- Anchor to localelocale•String
The company contact's locale (language).
- Anchor to titletitle•String
The company contact's job title.
- Anchor to updatedAtupdated•
At DateTime! non-null The date and time (ISO 8601 format) at which the company contact was last modified.
- Anchor to locationlocation•Company
Location! non-null The company location associated to the order or draft order.
- Anchor to createdAtcreated•
At DateTime! non-null The date and time (ISO 8601 format) at which the company location was created in Shopify.
- Anchor to externalIdexternal•
Id String A unique externally-supplied ID for the company.
- •ID!non-null
The ID of the company.
- Anchor to localelocale•String
The preferred locale of the company location.
- Anchor to metafieldmetafield•Metafield
A custom field that stores additional information about a Shopify resource, such as products, orders, and many more. Using metafields with Shopify Functions enables you to customize the checkout experience.
- Anchor to namespacenamespace•String
A category that organizes a group of metafields. Namespaces are used to prevent naming conflicts between different apps or different parts of the same app. If omitted, then the app-reserved namespace is used.
- •String!required
The unique identifier for the metafield within its namespace. A metafield is composed of a namespace and a key, in the format
namespace.key
.
Arguments
- Anchor to jsonValuejson•
Value JSON!non-null The data that's stored in the metafield, using JSON format.
- Anchor to typetype•String!non-null
The type of data that the metafield stores in the
value
field.- Anchor to valuevalue•String!non-null
The data that's stored in the metafield. The data is always stored as a string, regardless of the metafield's type.
Fields
- Anchor to namename•String!non-null
The name of the company location.
- Anchor to updatedAtupdated•
At DateTime! non-null The date and time (ISO 8601 format) at which the company location was last modified.
- Anchor to lineslines•[Cart
Line!]! non-null The items in a cart that the customer intends to purchase. A cart line is an entry in the customer's cart that represents a single unit of a product variant. For example, if a customer adds two different sizes of the same t-shirt to their cart, then each size is represented as a separate cart line.
- Anchor to attributeattribute•Attribute
The custom attributes associated with a cart to store additional information. Cart attributes allow you to collect specific information from customers on the Cart page, such as order notes, gift wrapping requests, or custom product details. Attributes are stored as key-value pairs.
Cart line attributes are equivalent to the
object in Liquid.
- •String
The key of the cart attribute to retrieve. For example,
.
Arguments
- •String!non-null
The key or name of the attribute. For example,
.
- Anchor to valuevalue•String
The value of the attribute. For example,
"true"
.
Fields
- •
- Anchor to costcost•Cart
Line Cost! non-null The cost of an item in a cart that the customer intends to purchase. Cart lines are entries in the customer's cart that represent a single unit of a product variant. For example, if a customer adds two different sizes of the same t-shirt to their cart, then each size is represented as a separate cart line.
- Anchor to amountPerQuantityamount•
Per Quantity MoneyV2! non-null The cost of a single unit. For example, if a customer purchases three units of a product that are priced at $10 each, then the
is $10.
- Anchor to amountamount•Decimal!non-null
A monetary value in decimal format, allowing for precise representation of cents or fractional currency. For example, 12.99.
- Anchor to currencyCodecurrency•
Code CurrencyCode! non-null The three-letter currency code that represents a world currency used in a store. Currency codes include standard standard ISO 4217 codes, legacy codes, and non-standard codes. For example, USD.
AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BDT, BGN, BHD, BIF, BMD, BND, BOB, BRL, BSD, BTN, BWP, BYN, BZD, CAD, CDF, CHF, CLP, CNY, COP, CRC, CVE, CZK, DJF, DKK, DOP, DZD, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JEP, JMD, JOD, JPY, KES, KGS, KHR, KID, KMF, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LTL, LVL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRU, MUR, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR, RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK, SGD, SHP, SLL, SOS, SRD, SSP, STN, SYP, SZL, THB, TJS, TMT, TND, TOP, TRY, TTD, TWD, TZS, UAH, UGX, USD, UYU, UZS, VED, VES, VND, VUV, WST, XAF, XCD, XOF, XPF, XXX, YER, ZAR, ZMW, BYR, STD, VEF
- Anchor to compareAtAmountPerQuantitycompare•
At Amount Per Quantity MoneyV2 The cost of a single unit before any discounts are applied. This field is used to calculate and display savings for customers. For example, if a product's
is $25 and its current price is $20, then the customer sees a $5 discount. This value can change based on the buyer's identity and is
null
when the value is hidden from buyers.- Anchor to amountamount•Decimal!non-null
A monetary value in decimal format, allowing for precise representation of cents or fractional currency. For example, 12.99.
- Anchor to currencyCodecurrency
Code