Cart attributes empty when using "Buy it Now" button

Topic summary

Cart-level attributes added via cart/update.js are available in checkout and order-status extensions after “Add to Cart,” but appear empty when using “Buy it Now.”

Buy It Now (express checkout) bypasses the add-to-cart step, so cart attributes may not be set or carried into checkout in this flow.

Proposed workaround: use line item properties (per-product/variant metadata) via cart/add.js. These properties are accessible in checkout extensions and work with both Add to Cart and Buy It Now.

Constraint: the original data is generic (cart-level, not tied to a specific item). The thread asks how to structure such non-item data and whether line item properties support private values (like the cart attribute “__” prefix). No guidance was provided on these points.

Outcome: No resolution; behavior appears by design rather than a documented bug. Open questions remain on storing cart-level metadata for express checkout and applying privacy to line item properties.

Note: Code snippets are central to the issue and the suggested implementation.

Summarized with AI on December 10. AI used: gpt-5.

I am adding some attribute data to the cart on the product page, using a script like:

const formData = new FormData();
formData.append("attributes[key]", value);
fetch(window.Shopify.routes.root + 'cart/update.js', {
    method: 'POST',
    body: formData
})

When I click “Add to Cart”, and follow the checkout flow, I can access the attribute in both checkout-ui extension, and order-status-ui extensions using something like:

// Via subscription
const { attributes } = useApi();
console.log("attributes", attributes)
const subscribedAttributes = useSubscription(attributes);
console.log("subscribedAttributes", subscribedAttributes);

// Via hook
const hookAttributes = useAttributes()
console.log("attributes", hookAttributes)
const [value] = useAttributeValues(["key"])
console.log("value", value)

And this works succesfully.

However, if I click “Buy it Now”, the attributes are empty, as if they were never set.

Why is this? This feels like undocumented behaviour / a bug? How can I access attribute data consistently in the checkout / order confirmation.

1 Like

Hey @joesaunderson

For your use case, I’d recommend Line item properties because they are more reliable than cart attributes for express checkout.

// Instead of cart attributes, add properties to the line item
const formData = new FormData();
formData.append('id', variantId);
formData.append('quantity', 1);
formData.append('properties[key]', value); // Line item property

fetch(window.Shopify.routes.root + 'cart/add.js', {
  method: 'POST',
  body: formData
});

Then in your checkout extensions:

// Access line item properties
const lines = useCartLines();
lines.forEach(line => {
  const property = line.attributes.find(attr => attr.key === 'key');
  console.log('Property value:', property?.value);
});

It with both Add to Cart and Buy it Now and is also attached to the specific product/variant.

Cheers,
Moeed

Hi Moeed,

Thanks for taking the time to reply.

In this case, the data doesn’t relate to an item… it’s generic data that might not even be related to the items in the cart.

How would you structure that? And is the line item data private in the same way the attributes can be (using the __ prefix).

Buy it now will take the current variation directly to the checkout page, bypassing the add to cart step.