# WooCommerce new order notifications on your phone

> Get a push notification with the customer, total and item count every time a new order is placed in your WooCommerce store.

- Company: WooCommerce (https://www.justpush.io/recipes/woocommerce)
- Event: `order.created` (Order created)
- Tags: E-commerce, Orders
- Install: https://studio.justpush.io/recipes/woocommerce/order-created
- Web page: https://www.justpush.io/recipes/woocommerce/order-created

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. In your WordPress admin, go to WooCommerce > Settings > Advanced > Webhooks and click Add webhook.
3. Set Status to Active, Topic to Order created, and API version to WP REST API Integration v3.
4. Paste your webhook URL (shown in Studio after install) as the Delivery URL and save. WooCommerce sends a ping right away to confirm it works.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// WooCommerce → order.created
// Docs: https://woocommerce.com/document/webhooks/
//
// Add a webhook under WooCommerce > Settings > Advanced > Webhooks with the topic
// "Order created" and API version v3, pointing at your integration's endpoint URL.

// WooCommerce prices are decimal strings ("49.00"). Returns null when there's no amount.
function money(amount, currency) {
    const value = Number(amount)

    if (amount == null || amount === "" || !Number.isFinite(value) || !currency) return null

    try {
        return new Intl.NumberFormat("en-GB", { style: "currency", currency }).format(value)
    } catch {
        return `${amount} ${currency}`
    }
}

// Header names can arrive in any case.
function header(request, name) {
    const headers = request.headers || {}
    const key = Object.keys(headers).find((k) => k.toLowerCase() === name)
    const value = key ? headers[key] : null
    return Array.isArray(value) ? value[0] : value
}

// X-WC-Webhook-Source is your store's URL, e.g. "https://shop.example.com/".
function adminUrl(request, path) {
    const source = header(request, "x-wc-webhook-source")
    return typeof source === "string" && /^https?:\/\//.test(source)
        ? source.replace(/\/?$/, "/") + "wp-admin/" + path
        : null
}

function handleRequest(request) {
    const body = request.body && typeof request.body === "object" ? request.body : {}

    // Saving a webhook makes WooCommerce send a ping (just a webhook_id); confirm it quietly.
    if (body.webhook_id && !body.id) {
        return {
            title: "🔔 WooCommerce connected",
            message: `Webhook #${body.webhook_id} is working`,
            topic: "WooCommerce",
            priority: -1,
        }
    }

    // Guard: only handle this topic, so other WooCommerce webhooks on this integration stay quiet.
    const topic = header(request, "x-wc-webhook-topic")

    if (topic && topic !== "order.created") {
        console.log(`Ignoring WooCommerce topic "${topic}"`)
        return null
    }

    const order = body

    if (!order.id || !Array.isArray(order.line_items)) {
        console.log("Not a WooCommerce order payload — skipping")
        return null
    }

    const billing = order.billing ?? {}
    const customer = [billing.first_name, billing.last_name].filter(Boolean).join(" ") || billing.company || "A guest"
    const total = money(order.total, order.currency)
    const number = order.number ?? order.id
    const link = adminUrl(request, `admin.php?page=wc-orders&action=edit&id=${order.id}`)
    const items = order.line_items.reduce((sum, item) => sum + (Number(item.quantity) || 0), 0)
    const via = order.payment_method_title ? ` via ${order.payment_method_title}` : ""
    // order.created fires at checkout, before some payment methods have finished.
    const waiting = {
        pending: " (awaiting payment)",
        "on-hold": " (on hold)",
        failed: " (payment failed)",
    }[order.status] ?? ""

    return {
        title: `🛒 New order #${number}${waiting}`,
        message:
            `${customer} ordered ${items} item${items === 1 ? "" : "s"}` +
            (total ? ` for ${total}` : "") +
            via,
        topic: "WooCommerce",
        priority: 1, // High — a sale is worth surfacing promptly
        sound: "cashregister",
        buttons: link ? [{ cta: "View order", url: link }] : [],
    }
}
```

## WooCommerce order.created webhook payload (sample)

```json
{
  "id": 1234,
  "total": "49.00",
  "number": "1234",
  "status": "processing",
  "billing": {
    "email": "jane@example.com",
    "company": "",
    "country": "NL",
    "last_name": "Doe",
    "first_name": "Jane"
  },
  "currency": "EUR",
  "total_tax": "8.50",
  "line_items": [
    {
      "id": 1,
      "name": "Enamel Pin",
      "total": "24.00",
      "quantity": 2,
      "product_id": 101
    },
    {
      "id": 2,
      "name": "Sticker Pack",
      "total": "16.50",
      "quantity": 1,
      "product_id": 102
    }
  ],
  "date_created": "2026-09-28T11:30:00",
  "payment_method": "mollie_wc_gateway_ideal",
  "payment_method_title": "iDEAL"
}
```

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into WooCommerce and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
