Examples

Up unpacked friendly ecstatic so possible humoured do. Ample end might folly quiet one set spoke her.

Reminder to thank big spenders

Use this hook as a reminder to personally thank a customer who has made a big purchase. The customer will also be tagged so that you can keep track of and build stronger relationships with your best customers.

The minimumPurchase variable is useful for setting a dollar amount, over which, you want to be notified about the order.

Reminder to thank big spenders
module.exports = async (order, actions, { shopUrl }) => {

  // Adjust these variables to customize
  const minimumPurchase = 100 // in dollars
  const tag = 'big-spender'
  const to = '[email protected]'
  const subject = `(${shopUrl}) Large order created`
  const body = `

${order.customer.email} just made a large order of $${order.total_price}.
Maybe you want to thank them personally?
Order: ${order.order_id}

` if (parseInt(order.total_price) > minimumPurchase) { await actions.shopify.tagCustomer(order.customer.id, tag) await actions.email.send({ to, subject, body }) } }

Email me when a refund is requested

Use this hook to find out when some customer support is needed! This is a great opportunity to reach out and change an unhappy customer to a loyal one.

The refundMinimum variable is useful for setting a dollar amount, over which, you want to be notified for a given refund. Default is $0, so you will receive an email for every refund.

Email me when a refund is requested
module.exports = async (refund, actions, { shopUrl }) => {

  // Adjust these variables to customize
  const refundMinimum = 0
  const to = '[email protected]'
  const subject = `(${shopUrl}) Refund requested`
  const body = `

Please review the following refund: ${refund.order_id}

` const totalRefundAmount = refund.refund_line_items.reduce((total, item) => { return total + parseInt(item.subtotal) }, 0) if (totalRefundAmount > refundMinimum) { await actions.email.send({ to, subject, body }) } }

How to use cart attributes in your hook

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".

Here is how the "Website URL" attribute looks on the cart page:

This is the hook code that logs the value of the cart attribute:

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.`)
	}
};
On this page