Skip to content

Abandoned cart emails for your store.

Remind shoppers who started a checkout and didn't finish. Your store sends two events, and the ready-made Abandoned cart automation in Sendicorn sends the emails.

How it works.

  1. 01

    A checkout starts

    Your store sends Checkout Started once the shopper has typed their email address.

  2. 02

    An hour, then a day

    If no Purchase came in, the first reminder goes out an hour later and the second a day later.

  3. 03

    A purchase stops it

    A Purchase from the same address stops the reminders right away.

Before you start

  • In Sendicorn, open Automations, then New automation, and click Use this on Abandoned cart. It's added switched off, so you can read the two emails and make them yours first.
  • Create an API key under API keys that can “Send emails and record events”. That's all the events need.

Who gets the reminders

They're marketing emails with an unsubscribe link, so they go to shoppers on your list. A shopper who isn't subscribed is skipped. If your newsletter asks new subscribers to confirm, reminders start with the checkouts they begin after confirming. The emails promise no discount: add one yourself if you want to. Your store sends a shopper's email address to Sendicorn when they start a checkout, so mention it in your privacy policy.

Shopify.

There's no app to install yet. You add three webhooks in Shopify and paste a small forwarder into a free Cloudflare Worker, which checks that each webhook really came from your store and passes it on. It takes about 15 minutes with no coding, but if you've never used Cloudflare, a developer can do it for you.
  1. 1In Sendicorn, create an API key that can “Send emails and record events” and “Add, read, change and export contacts”. The second lets shoppers who tick Shopify's “Email me with news and offers” box join your list.
  2. 2In Cloudflare, go to Workers & Pages, create a Worker from the Hello World template and deploy it. Click Edit code, replace everything with the code below, and deploy again. Copy the Worker's address, which ends in workers.dev.
  3. 3In Shopify, open Settings, then Notifications, then Webhooks. Click Create webhook three times, once for each event: Checkout creation, Checkout update and Order creation. Format JSON, the Worker's address as the URL, and the newest API version.
  4. 4Shopify shows the key your webhooks are signed with on the same page. In the Worker's Settings, under Variables and Secrets, add it as a secret named SHOPIFY_WEBHOOK_KEY, your Sendicorn key as a secret named SENDICORN_API_KEY, and your newsletter's link name as a text variable named SENDICORN_NEWSLETTER. Webhooks that arrive before the secrets are in fail, and Shopify sends them again later.
  5. 5Turn off Shopify's own abandoned checkout email (Marketing, then Automations, or Settings, then Checkout, on some stores), so shoppers don't get both. Then turn on Abandoned cart in Sendicorn and start a checkout with your own address to see it arrive in the automation's runs.

worker.js · Cloudflare Worker

// Shopify webhooks to Sendicorn: checkouts become "Checkout Started", orders become "Purchase".
// Secrets: SHOPIFY_WEBHOOK_KEY (from Shopify) and SENDICORN_API_KEY (from Sendicorn).
// Optional variable: SENDICORN_NEWSLETTER, your newsletter's link name.
const API = "https://app.sendicorn.com/api/v1";

export default {
  async fetch(request, env) {
    if (request.method !== "POST") return new Response("Send Shopify webhooks here.");
    const body = await request.text();
    const signature = request.headers.get("X-Shopify-Hmac-Sha256");
    if (!(await isFromShopify(body, signature, env.SHOPIFY_WEBHOOK_KEY))) {
      return new Response("Bad signature", { status: 401 });
    }

    const topic = request.headers.get("X-Shopify-Topic");
    const data = JSON.parse(body);
    const email = data.email || data.customer?.email;
    if (!email) return new Response("No email yet");
    const newsletter = env.SENDICORN_NEWSLETTER || undefined;
    const currency = data.presentment_currency || data.currency;

    if (topic === "checkouts/create" || topic === "checkouts/update") {
      if (data.completed_at) return new Response("Already bought");
      // Shoppers who ticked "Email me with news and offers" join your list, so they can get reminders.
      if (data.buyer_accepts_marketing && newsletter) {
        await send(env, "/contacts", { newsletter, email, source: "shopify-checkout", consent: true });
      }
      await send(env, "/events", {
        email,
        name: "Checkout Started",
        newsletter,
        uniqueId: data.token,
        time: data.updated_at || undefined,
        properties: {
          checkout_id: data.token,
          checkout_url: data.abandoned_checkout_url,
          total: data.total_price,
          currency,
          first_name: data.customer?.first_name || data.billing_address?.first_name || undefined,
          items: (data.line_items || []).map((item) => ({ name: item.title, quantity: item.quantity, price: item.price })),
        },
      });
    } else if (topic === "orders/create") {
      await send(env, "/events", {
        email,
        name: "Purchase",
        newsletter,
        uniqueId: String(data.id),
        time: data.created_at || undefined,
        properties: {
          order_id: String(data.id),
          checkout_id: data.checkout_token || undefined,
          total: data.total_price_set?.presentment_money?.amount || data.total_price,
          currency: data.total_price_set?.presentment_money?.currency_code || currency,
        },
      });
    }
    return new Response("OK");
  },
};

// Busy or down: fail, so Shopify sends the webhook again later. Repeats count once.
async function send(env, path, payload) {
  const response = await fetch(API + path, {
    method: "POST",
    headers: { Authorization: `Bearer ${env.SENDICORN_API_KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify(payload),
  });
  if (response.status === 429 || response.status >= 500) throw new Error(`${path} answered ${response.status}`);
  if (!response.ok) console.log(`${path} answered ${response.status}`);
}

async function isFromShopify(body, signature, secret) {
  if (!signature || !secret) return false;
  try {
    const encoder = new TextEncoder();
    const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["verify"]);
    const expected = Uint8Array.from(atob(signature), (char) => char.charCodeAt(0));
    return await crypto.subtle.verify("HMAC", key, expected, encoder.encode(body));
  } catch {
    return false;
  }
}

Shopify sends a checkout again every time the shopper changes it. Only the first one counts, so each checkout gets one set of reminders. A finished checkout and any order from the same address stop them.

WooCommerce.

One plugin file and two lines in wp-config.php. It works with the classic and the block checkout, and the reminder's link puts the shopper's cart back for a week, on any device where their cart is empty.
  1. 1In Sendicorn, create an API key that can “Send emails and record events”.
  2. 2Add the lines below to wp-config.php, above the line that says to stop editing. Keep your key there, never in the plugin file or the database.
  3. 3Save the plugin as wp-content/plugins/sendicorn-abandoned-cart.php (with your host's file manager or SFTP), then activate it under Plugins.
  4. 4Turn on Abandoned cart in Sendicorn and start a checkout with your own address to test it.

wp-config.php · add these lines

define('SENDICORN_API_KEY', 'sc_live_your_key');
// Only if you have more than one newsletter: the link name of the one shoppers join.
define('SENDICORN_NEWSLETTER', 'your-newsletter');

sendicorn-abandoned-cart.php · plugin

<?php
/**
 * Plugin Name: Sendicorn abandoned cart
 * Description: Sends Checkout Started and Purchase to Sendicorn, and opens a saved cart from the reminder's link.
 * Version: 1.0
 */

if (!defined('ABSPATH')) {
    exit;
}

function sendicorn_event(array $body) {
    if (!defined('SENDICORN_API_KEY')) {
        return;
    }
    if (defined('SENDICORN_NEWSLETTER') && SENDICORN_NEWSLETTER) {
        $body['newsletter'] = SENDICORN_NEWSLETTER;
    }
    $response = wp_remote_post('https://app.sendicorn.com/api/v1/events', array(
        'timeout' => 3,
        'headers' => array(
            'Authorization' => 'Bearer ' . SENDICORN_API_KEY,
            'Content-Type'  => 'application/json',
        ),
        'body'    => wp_json_encode($body),
    ));
    if (is_wp_error($response) || wp_remote_retrieve_response_code($response) >= 300) {
        error_log('Sendicorn: ' . $body['name'] . ' was not recorded');
        return false;
    }
    return true;
}

// One ID per cart, kept in the shopper's WooCommerce session.
function sendicorn_checkout_id() {
    $id = WC()->session->get('sendicorn_checkout_id');
    if (!$id) {
        $id = wp_generate_uuid4();
        WC()->session->set('sendicorn_checkout_id', $id);
    }
    return $id;
}

function sendicorn_checkout_started($email, $first_name = '') {
    $email = sanitize_email($email);
    if (!is_email($email) || !WC()->session || !WC()->cart || WC()->cart->is_empty()) {
        return;
    }
    $id = sendicorn_checkout_id();
    $items = array();
    $saved = array();
    foreach (WC()->cart->get_cart() as $item) {
        $items[] = array(
            'name'     => $item['data']->get_name(),
            'quantity' => (int) $item['quantity'],
            'price'    => wc_format_decimal(($item['line_total'] + $item['line_tax']) / max(1, (int) $item['quantity']), wc_get_price_decimals()),
        );
        $saved[] = array(
            'product_id'   => $item['product_id'],
            'variation_id' => $item['variation_id'],
            'variation'    => $item['variation'],
            'quantity'     => $item['quantity'],
        );
    }
    // Kept for a week, so the reminder's link can open the cart on any device.
    set_transient('sendicorn_cart_' . $id, $saved, WEEK_IN_SECONDS);
    if (WC()->session->get('sendicorn_sent_for') === $email . $id) {
        return;
    }
    $properties = array(
        'checkout_id'  => $id,
        'checkout_url' => add_query_arg('sendicorn_cart', $id, wc_get_checkout_url()),
        'total'        => wc_format_decimal(WC()->cart->get_total('edit'), wc_get_price_decimals()),
        'currency'     => get_woocommerce_currency(),
        'items'        => $items,
    );
    if ($first_name) {
        $properties['first_name'] = sanitize_text_field($first_name);
    }
    $sent = sendicorn_event(array(
        'email'      => $email,
        'name'       => 'Checkout Started',
        'uniqueId'   => $id,
        'properties' => $properties,
    ));
    // Only once it went through, so a failed send is tried again on the shopper's next change.
    if ($sent) {
        WC()->session->set('sendicorn_sent_for', $email . $id);
    }
}

// Classic checkout: runs when the shopper fills in the form.
add_action('woocommerce_checkout_update_order_review', function ($posted) {
    parse_str($posted, $fields);
    if (!empty($fields['billing_email'])) {
        sendicorn_checkout_started($fields['billing_email'], isset($fields['billing_first_name']) ? $fields['billing_first_name'] : '');
    }
});

// Block checkout: runs when the shopper's details are saved.
add_action('woocommerce_store_api_cart_update_customer_from_request', function ($customer) {
    sendicorn_checkout_started($customer->get_billing_email(), $customer->get_billing_first_name());
});

// A placed order remembers its checkout, so the payment can be matched to it later.
function sendicorn_remember_checkout($order) {
    if ($order instanceof WC_Order && WC()->session && WC()->session->get('sendicorn_checkout_id')) {
        $order->update_meta_data('_sendicorn_checkout_id', WC()->session->get('sendicorn_checkout_id'));
        $order->save();
    }
}
add_action('woocommerce_checkout_order_processed', function ($order_id, $posted_data, $order) {
    sendicorn_remember_checkout($order);
}, 10, 3);
add_action('woocommerce_store_api_checkout_order_processed', 'sendicorn_remember_checkout');

// Purchase once the order is paid, or accepted to pay later (bank transfer, cash on delivery). A failed
// card sends nothing, so the reminders still go out. Repeats count once.
function sendicorn_purchase($order_id) {
    $order = wc_get_order($order_id);
    if (!$order) {
        return;
    }
    $properties = array(
        'order_id' => (string) $order->get_id(),
        'total'    => wc_format_decimal($order->get_total(), wc_get_price_decimals()),
        'currency' => $order->get_currency(),
    );
    $id = $order->get_meta('_sendicorn_checkout_id');
    if ($id) {
        $properties['checkout_id'] = $id;
        delete_transient('sendicorn_cart_' . $id);
    }
    sendicorn_event(array(
        'email'      => $order->get_billing_email(),
        'name'       => 'Purchase',
        'uniqueId'   => (string) $order->get_id(),
        'time'       => $order->get_date_created() ? $order->get_date_created()->format('c') : null,
        'properties' => $properties,
    ));
}
add_action('woocommerce_payment_complete', 'sendicorn_purchase');
add_action('woocommerce_order_status_processing', 'sendicorn_purchase');
add_action('woocommerce_order_status_on-hold', 'sendicorn_purchase');
add_action('woocommerce_order_status_completed', 'sendicorn_purchase');

// The order page: the next cart gets a new ID.
add_action('woocommerce_thankyou', function () {
    if (WC()->session) {
        WC()->session->set('sendicorn_checkout_id', null);
        WC()->session->set('sendicorn_sent_for', null);
    }
});

// The reminder's link: puts the saved cart back, then opens the checkout.
add_action('template_redirect', function () {
    if (empty($_GET['sendicorn_cart']) || !function_exists('WC') || !WC()->cart) {
        return;
    }
    $id = sanitize_key(wp_unslash($_GET['sendicorn_cart']));
    if (!preg_match('/^[a-f0-9-]{36}$/', $id)) {
        return;
    }
    $saved = get_transient('sendicorn_cart_' . $id);
    if (is_array($saved) && WC()->cart->is_empty()) {
        foreach ($saved as $item) {
            WC()->cart->add_to_cart($item['product_id'], $item['quantity'], $item['variation_id'], $item['variation']);
        }
        WC()->session->set('sendicorn_checkout_id', $id);
    }
    wp_safe_redirect(remove_query_arg('sendicorn_cart'));
    exit;
});

WooCommerce has no newsletter box of its own, so add shoppers to your list with your signup form or a plugin you already use: only subscribers get reminders. An order counts once it's paid, or accepted for bank transfer or cash on delivery, so a declined card still gets its reminders. A heavily customized checkout may need a developer to check the two checkout hooks.

Any other store.

Two requests from your server to POST /api/v1/events, with your key in the Authorization header. Use the event names exactly as written.

Checkout Started

email
The shopper's email address, at the top of the body.
checkout_id
Your store's ID for this checkout. Also send it as uniqueId: the same checkout sent again counts once.
checkout_url
A link that opens this cart again.
total
The cart total as text, like "59.90".
currency
The currency code, like USD or EUR. Without the link, total or currency, no reminder goes out.
first_nameoptional
Used in the greeting. Without it the email says "Hi there".
itemsoptional
The products, as a list of { name, quantity, price }. Kept with the event for your records.

Purchase

email
The same address the checkout had.
order_id
Your order ID. Also send it as uniqueId.
checkout_idoptional
The checkout the order came from, when you know it.

terminal · when a checkout starts

curl -X POST https://app.sendicorn.com/api/v1/events \
  -H "Authorization: Bearer $SENDICORN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "email": "[email protected]",
  "name": "Checkout Started",
  "uniqueId": "chk_1001",
  "properties": {
    "checkout_id": "chk_1001",
    "checkout_url": "https://shop.example.com/checkouts/chk_1001",
    "total": "59.90",
    "currency": "USD",
    "first_name": "Jane",
    "items": [
      {
        "name": "Canvas tote",
        "quantity": 1,
        "price": "24.90"
      },
      {
        "name": "Ceramic mug",
        "quantity": 2,
        "price": "17.50"
      }
    ]
  }
}'

terminal · when the order is placed

curl -X POST https://app.sendicorn.com/api/v1/events \
  -H "Authorization: Bearer $SENDICORN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "email": "[email protected]",
  "name": "Purchase",
  "uniqueId": "order_5001",
  "properties": {
    "order_id": "order_5001",
    "checkout_id": "chk_1001",
    "total": "59.90",
    "currency": "USD"
  }
}'

server.js · the same from JavaScript

// On your server, once the shopper has typed their email address.
await fetch("https://app.sendicorn.com/api/v1/events", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SENDICORN_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    email: shopper.email,
    name: "Checkout Started",
    uniqueId: checkout.id,
    properties: {
      checkout_id: checkout.id,
      checkout_url: checkout.url,
      total: checkout.total, // "59.90"
      currency: checkout.currency, // "USD"
      first_name: shopper.firstName,
      items: checkout.items, // [{ name, quantity, price }]
    },
  }),
});

// When the order is placed.
await fetch("https://app.sendicorn.com/api/v1/events", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SENDICORN_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    email: order.email,
    name: "Purchase",
    uniqueId: order.id,
    properties: { order_id: order.id, checkout_id: checkout.id },
  }),
});

Keep the key on your server, never in the browser. A successful request answers 202. Sending the same checkout or order again is safe: a repeated uniqueId counts once.

Start today.

Bring every project and every list.

Get started

No password to set. You sign in with a code. Setting up is free, and your account can send as soon as you choose a plan and pay.