Skip to content

Instantly share code, notes, and snippets.

View cloudhooks's full-sized avatar

Cloudhooks cloudhooks

View GitHub Profile
@cloudhooks
cloudhooks / access-cart-attributes.js
Created December 14, 2023 12:47
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;
@cloudhooks
cloudhooks / email-when-refund-requested.js
Created December 14, 2023 12:46
Use this hook to find out when some customer support is needed.
module.exports = async (refund, actions, { shopUrl }) => {
// Adjust these variables to customize
const refundMinimum = 0
const to = '[Your email address]'
const subject = `(${shopUrl}) Refund requested`
const body = `
Please review the following refund:
${refund.order_id}
`
@cloudhooks
cloudhooks / reminder-big-spender.js
Created December 14, 2023 12:44
Use this hook as a reminder to personally thank a customer who has made a big purchase.
module.exports = async (order, actions, { shopifyDomain }) => {
// Adjust these variables to customize
const minimumPurchase = 100 // in dollars
const tag = 'big-spender'
const to = '[email protected]'
const subject = `(${shopifyDomain}) Large order created`
const body = `
${order.customer.email} just made a large order of $${order.total_price}.
Maybe you want to thank them personally?
@cloudhooks
cloudhooks / mailerlite-subscriber.js
Last active December 14, 2023 12:42
Adds the customer's email address to MailerLite via the MailerLite API.
const apiKey = 'Your Mailerlite API key';
const subscriberGroups = ['Subscriber group id1', 'Subscriber group id2'];
module.exports = async function(payload, actions) {
const httpConfig = {
headers: {
'Authorization': `Bearer ${apiKey}`
}
};
@cloudhooks
cloudhooks / google-analytics-4.js
Created December 14, 2023 12:40
Sends a purchase event to Google Analytics (the hook expects an order payload)
const API_SECRET = '[Your GA4 API secret]';
const MEASUREMENT_ID = '[Your GA4 measurement id]';
module.exports = async function(payload, actions, context) {
const gaUrl = 'https://www.google-analytics.com/mp/collect' +
`?api_secret=${API_SECRET}` +
`&measurement_id=${MEASUREMENT_ID}`;
const gaData = {