Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.
Solved

How to add custom attributes to order at checkout

AW1234
Shopify Partner
44 7 11

Hi, I have a checkout app in wich I would like to add a "custom attribute" to the order

something like this (made with liquid)

AW1234_0-1706267242122.png

in my app now I have this

useEffect(() => {
    // fetching data
        await applyAttributeChange({ key: 'dal_min', value: json.dals[0].dalMin.slice(0, 10) });
        await applyAttributeChange({ key: 'dal_max', value: json.dals[0].dalMax.slice(0, 10) });
      } catch (err) {
        console.error(err)
      }
    }
    fetchDal();
  }, []);

I test in my dev store and when I make an order I don't have the data in my order when I look in my back office

AW1234_1-1706267386447.png

 

 

Did I make a mistake? is this a bug or is there no way to do that anymore?

 

Accepted Solution (1)

SBD_
Shopify Staff
1779 263 383

This is an accepted solution.

Hey @AW1234 

 

What do you see if you log the result?

const result = await applyAttributeChange({
  key: '...',
  type: 'updateAttribute',
  value: '...',
});
console.log(
  'applyAttributeChange result',
  result,
);

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 3 (3)

dylanpierce
Shopify Partner
203 3 91

Sounds like you're updating attributes on the cart not the order.

The Cart API is not the same as the Order API.

From what I understand, the `cart_token` is the only way to associate the cart with an order, and that's now deprecated. I would love if someone could point in the right direction of how to pass attributes from the cart to the order.


From what I can tell, there's no way to link a cart token to an order without relying on the Admin REST Order API which is deprecating the `cart_token` field.

Founder of Real ID - Verify your customer's real IDs easily & securely with modern AI

SBD_
Shopify Staff
1779 263 383

This is an accepted solution.

Hey @AW1234 

 

What do you see if you log the result?

const result = await applyAttributeChange({
  key: '...',
  type: 'updateAttribute',
  value: '...',
});
console.log(
  'applyAttributeChange result',
  result,
);

Scott | Developer Advocate @ Shopify 

AW1234
Shopify Partner
44 7 11

there were some errors and after fixing them it worked thank you.