# WooCommerce low or out of stock notifications on your phone > Get a push notification when a WooCommerce product runs low or sells out, with how many are left. - Company: WooCommerce (https://www.justpush.io/recipes/woocommerce) - Event: `product.updated` (Product updated) - Tags: E-commerce, Orders - Install: https://studio.justpush.io/recipes/woocommerce/stock-alert - Web page: https://www.justpush.io/recipes/woocommerce/stock-alert ## 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 Product updated, 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 → product.updated (low or out of stock) // Docs: https://woocommerce.com/document/webhooks/ // // Add a webhook under WooCommerce > Settings > Advanced > Webhooks with the topic // "Product updated" and API version v3, pointing at your integration's endpoint URL. // WooCommerce's default "low stock threshold" (Settings > Products > Inventory). // Change this if you've changed it there. const LOW_STOCK_DEFAULT = 2 // 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 !== "product.updated") { console.log(`Ignoring WooCommerce topic "${topic}"`) return null } const product = body if (!product.id || !product.name) { console.log("Not a WooCommerce product payload — skipping") return null } const managed = product.manage_stock === true && typeof product.stock_quantity === "number" const out = product.stock_status === "outofstock" || (managed && product.stock_quantity <= 0) // The product's own threshold if it has one, otherwise the store default of 2. const own = product.low_stock_amount const threshold = own !== null && own !== "" && Number.isFinite(Number(own)) ? Number(own) : LOW_STOCK_DEFAULT const low = managed && product.stock_quantity > 0 && product.stock_quantity <= threshold // product.updated fires for every change; only stock problems are worth a push. if (!out && !low) { console.log(`"${product.name}" has enough stock — skipping`) return null } const link = adminUrl(request, `post.php?post=${product.id}&action=edit`) const sku = product.sku ? ` (SKU ${product.sku})` : "" return { title: out ? "📦 Out of stock" : "📉 Low stock", message: out ? `${product.name}${sku} sold out` : `${product.name}${sku}: ${product.stock_quantity} left`, topic: "WooCommerce", priority: out ? 1 : 0, // High when you're losing sales, Normal as a heads-up buttons: link ? [{ cta: "View product", url: link }] : [], } } ``` ## WooCommerce product.updated webhook payload (sample) ```json { "id": 101, "sku": "PIN-01", "name": "Enamel Pin", "type": "simple", "price": "12.00", "status": "publish", "manage_stock": true, "stock_status": "instock", "stock_quantity": 2, "low_stock_amount": null } ``` ## 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.