Skip to content

Shopify Dude Fix

Shopify Private Cart Attributes vs Private Line Item Properties

Choose the right underscore convention for internal cart metadata and understand what the storefront can still read.

Quick answer: Use a double underscore prefix for private cart attributes and a single underscore prefix for private line item properties. They are not interchangeable: private line properties remain readable by theme code and the Ajax API, while private cart attributes are not exposed through those read surfaces.
On this page

Why internal metadata appears in the cart drawer

A fulfillment routing marker belongs to an individual line when it describes that item. A cart-wide campaign reference belongs to the cart. A theme that prints every line property will still display internal line markers unless its rendering logic filters them.

Implement the distinction

For an Ajax theme, attach a line marker through the properties object in cart/add.js. Set a cart-wide attribute through cart/update.js. Use locale-aware routes rather than hardcoding the root path.

fetch(window.Shopify.routes.root + 'cart/update.js', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({attributes: {__campaign_ref: 'spring'}})
});

For line properties, filter keys beginning with an underscore in each theme surface that renders them. Keep customer-facing personalization visible and escape output.

{% for property in item.properties %}
  {% assign prefix = property.first | slice: 0 %}
  {% unless prefix == '_' or property.last == blank %}
    {{ property.first | escape }}: {{ property.last | escape }}
  {% endunless %}
{% endfor %}

Inspect the cart page, drawer, quick-add and third-party cart widgets independently. Do not assume editing one Liquid snippet fixes all surfaces. Both types of private metadata can be visible in order administration.

Common misunderstanding: Private means secret or trusted. These fields are not a security boundary. Never store credentials or authorize discounts and fulfillment solely on buyer-controlled cart metadata.
How to test this:

  1. Add a disposable item with public personalization and a private line marker.
  2. Inspect cart JSON and confirm the line marker is present but not rendered in the drawer.
  3. Set a private cart attribute and verify it is absent from Ajax cart reads.
  4. Test the cart page and checkout, then place a test order and inspect order details.
  5. Confirm server-side rules reject manipulated metadata and that customer personalization remains visible.
Sources and further reading: Ajax Cart API; Liquid cart object.