Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
So I've added a script tag that adds a custom "ref" attribute via /cart/update.js to the customer's cart.
I've also set up a webhook that listens to the orders/paid event.
I've tried looking for the "ref" attribute everywhere but I can't find it. It's not in the order object, nor in the checkout object from /admin/api/2024-01/checkouts/[checkout_token].json.
The order object includes a cart_token but I can't figure out how to get a cart by it's token via API.
All of my app's logic is on the server side, there's no custom checkout UI or anything.
Figured it out! For future readers in a similar situation, you have to make sure your attribute names start with a "_" character - in my case it had to be "_ref". This way the attribute gets passed to the note_attributes array in the order object.
If there's anyone else stumbling across this via Google, I too was eventually able to update the `order.note_attributes` from the cart.
But unlike @rubby I was able to create a note attribute without the `_` prefix. A normal variable works fine.
1. Create a note attribute from the frontend of the online store:
```javascript
const formData = new FormData()
formData.append("attributes[your_attribute_name]", "your attribute value")
fetch(window.Shopify.routes.root + 'cart/update.js', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => console.log(data));
```
2. In the webhook, observe your attribute added as an entry `order.note_attributes`.
Another side effect is the note attribute is shown in the order page in the Shopify Admin. Might not be ideal if you need to store details that shouldn't be editable, like a unique ID number.
Want to see it in action? Check out our demo store.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024