Skip to content

Instantly share code, notes, and snippets.

@cloudhooks
Created December 14, 2023 12:47
Show Gist options
  • Save cloudhooks/a13aa9600ac370b1cd7bb343d0505b8b to your computer and use it in GitHub Desktop.
Save cloudhooks/a13aa9600ac370b1cd7bb343d0505b8b to your computer and use it in GitHub Desktop.
You can access cart attributes in your order-related hooks. As an example, we'll show you how to retrieve a cart attribute called "Website URL".
function findCartAttribute(payload, attributeName) {
let result = null;
if (payload.note_attributes && payload.note_attributes.length > 0) {
payload.note_attributes.every( attrib => {
if (attrib.name === attributeName) {
result = attrib.value;
return false;
}
return true;
});
}
return result;
}
module.exports = async function(payload, actions) {
const ATTRIB_NAME = 'Website URL';
const value = findCartAttribute(payload, ATTRIB_NAME);
if (value) {
console.log(`Cart attribute '${ATTRIB_NAME}' is '${value}'.`)
} else {
console.error(`Cart attribute '${ATTRIB_NAME}' is not in the payload.`)
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment