Solved

How to add custom attributes to order at checkout

AW1234
Shopify Partner
44 7 12

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
1829 269 406

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
211 3 95

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 A.I.

Want to see it in action? Check out our demo store.

SBD_
Shopify Staff
1829 269 406

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 12

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