Created
December 14, 2023 12:47
-
-
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".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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