Cart Transform: Update Lines Operation

Cart Transform: Update Lines Operation

The Update Lines transform allows you to modify the properties of cart line items, including their price, title, and image.

Overview

The Update Lines transform allows you to modify the properties of cart line items, including their price, title, and image. This is particularly useful for:

  • Dynamic pricing: Apply custom prices based on cart line attributes or metafields
  • Product customization: Change titles and images based on customer selections
  • Personalization: Display customized product information in the cart
  • Conditional pricing: Apply different prices based on product attributes

When cart lines are updated, the modifications appear immediately in the customer’s cart, providing a dynamic and personalized shopping experience.

Note: this operation is supported on the Shopify Plus stores only.

How to Configure Updates

You can configure line updates in two ways:

  1. Manual Configuration: Set fixed values for price, title, and image in the Function Studio interface
  2. Attribute-Based Configuration: Load all values dynamically from a cart line attribute

Both methods provide powerful ways to customize the cart experience based on your business needs.

Method 1: Manual Configuration

Adding the Update Action

  1. In your cart transform function, click Add Action
  2. Select Update Lines from the action list
  3. Configure the action settings in the panel

Configuration Options

Cart Line Groups

  • Select which groups of cart lines should be updated
  • Groups must be defined earlier in your function using “Define Cart Line Groups”
  • Example: Select “CUSTOM_PRODUCTS” or “PERSONALIZED_ITEMS”

Price Configuration

You have two options for setting the price:

Option A: Fixed Price

  • Enter a specific price amount
  • This price will be applied to all matching cart lines
  • Useful for promotional pricing or fixed-rate customizations

Option B: Load Price from Field

  • Enable “Load price from field” toggle
  • Select a field source:
    • Cart Line Attribute: Use an attribute value from the cart line
    • Standard Field: Use a built-in product/variant field
  • The field value will be used as the price for each cart line

Title Configuration

  • Enter a custom title for the cart line
  • This replaces the default product/variant title
  • Useful for personalized products or custom configurations
  • Leave empty to keep the original title

Image Configuration

  • Select or enter an image URL (must be hosted on Shopify CDN)
  • This replaces the default product/variant image
  • Useful for showing customized products or variations
  • Leave empty to keep the original image

Method 2: Attribute-Based Configuration

Overview

For maximum flexibility, you can load all fields (price, title, and image) from a single cart line attribute. This is ideal for highly dynamic scenarios where values are set programmatically.

Enabling Attribute-Based Loading

  1. In the Update Lines action, enable “Load all fields from attribute”
  2. Specify the Attribute key (defaults to _update)
  3. Set the attribute value on your cart lines with a JSON object

Attribute JSON Structure

The cart line attribute should contain a JSON object with these properties:

{
  "price": "34.56",
  "title": "Custom Product Title",
  "image": "https://cdn.shopify.com/path/to/image.png"
}

Attribute Object Properties

price (String, Optional)

  • The new price per unit for this cart line
  • Must be a string representation of a decimal number
  • Example: "29.99" or "125.50"
  • If omitted, the price is not changed

title (String, Optional)

  • The new title for this cart line
  • Replaces the default product/variant title
  • Example: "Personalized T-Shirt - John"
  • If omitted, the title is not changed

image (String, Optional)

  • The new image URL for this cart line
  • Must be a valid URL to an image file
  • Example: "https://cdn.shopify.com/s/files/1/0896/4138/6248/files/custom-image.png"
  • If omitted, the image is not changed

Setting the Attribute

The attribute can be set through various methods:

In Product Forms (Liquid Templates)

<input type="hidden" name="properties[_update]" value='{"price":"34.56","title":"Custom Product"}'>

Via Ajax Cart API

{
  "id": "12345",
  "qty": 1,
  "properties": {
    "_update": '{"price":"34.56","title":"Custom Product","image":"https://example.com/image.png"}'
  }
}

Through Shopify Scripts or Apps

  • Set the property when adding items to cart programmatically
  • Useful for product configurators or customization tools
  • Can be dynamically generated based on customer selections

Configuration Examples

Example 1: Fixed Price Override

Scenario: Apply a promotional price to all items in a specific collection

Function Studio Setup:

  1. Create a “Define Cart Line Groups” action:
    • Group name: PROMO_ITEMS
    • Condition: Product is in collection “Summer Sale”
  2. Add an “Update Lines” action:
    • Cart Line Groups: Select PROMO_ITEMS
    • Price: Enter 19.99
    • Title: Leave empty (keep original)
    • Image: Leave empty (keep original)

Result: All items in the “Summer Sale” collection are repriced to $19.99

Example 2: Load Price from Metafield

Scenario: Use a custom price stored in a product metafield

Product Setup:

  • Add a metafield to products: custom.special_price (type: Number)
  • Set value: 24.99

Function Studio Setup:

  1. Create a “Define Cart Line Groups” action with group name CUSTOM_PRICED
  2. Add an “Update Lines” action:
    • Cart Line Groups: Select CUSTOM_PRICED
    • Enable “Load price from field”
    • Select Product Metafield
    • Choose namespace: custom, key: special_price

Result: Each product uses its custom.special_price metafield value as the price

Example 3: Dynamic Customization with Attributes

Scenario: Customer personalizes a product with custom text and image

Cart Line Setup: Add this when the customer adds to cart:

{
  "id": "12345",
  "quantity": 1,
  "properties": {
    "_update": '{"price":"45.00","title":"Personalized Mug - Sarah","image":"https://cdn.shopify.com/generated/sarah-mug.png"}'
  }
}

Function Studio Setup:

  1. Create a “Define Cart Line Groups” action:
    • Group name: PERSONALIZED
    • Condition: Has attribute _update
  2. Add an “Update Lines” action:
    • Cart Line Groups: Select PERSONALIZED
    • Enable “Load all fields from attribute”
    • Attribute key: _update

Result: Cart line displays custom title, image, and price based on the personalization

Example 4: Variant-Specific Pricing

Scenario: Different variants have different promotional prices stored in variant metafields

Variant Setup:

  • Variant A: metafield custom.promo_price = 29.99
  • Variant B: metafield custom.promo_price = 39.99

Function Studio Setup:

  1. Create a “Define Cart Line Groups” action with group name ON_SALE
  2. Add an “Update Lines” action:
    • Cart Line Groups: Select ON_SALE
    • Enable “Load price from field”
    • Select Variant Metafield
    • Choose namespace: custom, key: promo_price

Result: Each variant uses its own promotional price from the metafield

Example 5: Custom Title for Bundles

Scenario: Show a custom title for bundle products

Function Studio Setup:

  1. Create a “Define Cart Line Groups” action:
    • Group name: BUNDLES
    • Condition: Product type is “Bundle”
  2. Add an “Update Lines” action:
    • Cart Line Groups: Select BUNDLES
    • Title: Complete Bundle - Special Offer
    • Leave price and image empty

Result: All bundle products display “Complete Bundle - Special Offer” as their title

Advanced Use Cases

Conditional Pricing Based on Quantity

Combine with conditions to apply different pricing based on cart line quantity:

Setup:

  1. Define multiple cart line groups based on quantity ranges
  2. Apply different update actions to each group with appropriate pricing

Multi-Tier Pricing from Attributes

Use attributes to implement complex pricing logic:

{
  "price": "19.99",
  "title": "Bulk Discount Applied - 20% OFF",
  "image": "https://cdn.shopify.com/sale-badge.png"
}

Product Configurator Integration

For products with complex configurations:

  1. Use a product configurator app or custom form
  2. Generate the _update attribute with calculated price and custom title
  3. Include a preview image URL showing the configured product
  4. Add to cart with all customization data