Woo Custom Events
Woo runtime events are browser CustomEvent objects. They bubble, so you can listen on a component, a nearby wrapper, or document.
Use events as the integration contract for work that happens after a Woo action. Do not use data-ome-state="success" as an integration contract; that state is visible UI feedback for the control that just finished an action.
Which Event Should I Use?
| Goal | Event |
|---|---|
| Open a mini-cart, track an add-to-cart conversion, or inspect the product that was added. | ome-woo:item-added |
| Refresh any cart-related integration after add, quantity update, or item removal. | ome-woo:cart-updated |
| Track add-to-cart failures. | ome-woo:add-to-cart-error |
| React to quantity changes or item removal with row-level detail. | ome-woo:item-quantity-updated or ome-woo:item-removed |
| React to committed variable-product selection state inside a Product Provider. | ome-woo:variation-selection-changed |
| Track checkout start, completion, and checkout errors. | ome-woo:checkout-started, ome-woo:checkout-complete, ome-woo:checkout-error |
| Track a completed purchase (thank-you page) with full order totals and items. | ome-woo:purchase |
ome-woo:item-added fires first for successful add-to-cart and includes product_id, quantity, cart_summary, and — when the add response provides them — variation_id, variation, and price. ome-woo:cart-updated follows when the integration only needs to know that the cart changed.
Analytics integrations do not need to listen for add/remove at all: OME also dispatches the standard wc-blocks_added_to_cart / wc-blocks_removed_from_cart DOM events and the legacy jQuery added_to_cart / removed_from_cart events (when jQuery is present). See Standard Analytics Bridge Events.
Event Summary
| Area | Event | Dispatch target | Detail payload |
|---|---|---|---|
| Cart boot | ome-woo:cart-loaded | First cart display root found, or document.body. | { cart_summary } |
| Product add | ome-woo:item-added | Standalone add button or submitted AddToCartForm. | { product_id, quantity, cart_summary, variation_id?, variation?, price? } |
| Product add | ome-woo:cart-updated | Same target as the successful cart mutation. | { cart_summary } |
| Product add | ome-woo:add-to-cart-error | Standalone add button or submitted AddToCartForm. | { product_id, quantity, error } |
| Analytics bridge | wc-blocks_added_to_cart | document.body. | { preserveCartData } |
| Analytics bridge | wc-blocks_removed_from_cart | document.body. | { preserveCartData } |
| Order received | ome-woo:purchase | document.body. | { order } |
| Product selection | ome-woo:variation-selection-changed | Nearest ProductProvider root. | { product_id, selection, selected_variation, current_product } |
| Cart item mutation | ome-woo:item-quantity-updated | Cart item quantity input. | { key, quantity, cart_summary } |
| Cart item mutation | ome-woo:item-removed | Cart item remove button, or document.body if the button was detached first. | { key, cart_summary } |
| Cart item mutation | ome-woo:cart-error | Cart item quantity input or remove button. | { action, key, quantity?, error } |
| Checkout | ome-woo:checkout-loaded | Checkout provider, checkout form, checkout notices, or document.body. | { checkout } |
| Checkout | ome-woo:checkout-started | Checkout form. | {} |
| Checkout | ome-woo:checkout-complete | Checkout form. | { checkout } |
| Checkout | ome-woo:checkout-error | Checkout form. | { errors?, phase?, source?, error?, diagnostic? } |
Shared Payload Shapes
cart_summary is the live cart summary after the mutation:
type WooCartSummary = {
item_count: number;
line_count: number;
};
error is a safe Woo error summary:
type WooErrorSummary = {
code: string;
message: string;
status: number;
field_keys?: string[];
};
checkout is the current Store API checkout response. It can include fields such as order_id, status, order_key, payment_method, payment_result, and __experimentalCart.
diagnostic is present on payment adapter failures when the adapter can provide a safe diagnostic object. It can include methodId, adapterId, provider, paymentType, fieldMode, phase, code, message, details, and sequence.
Product Selection Event
ome-woo:variation-selection-changed
| Contract | Value |
|---|---|
| Dispatch target | The nearest OmeWooProductProvider root. Standalone AddToCartForm does not emit this event. |
| Bubbles | Yes. |
| Composed | Yes. |
| Cancelable | No. |
| When it fires | After Provider datasets and form mirrors have committed a new semantic variable-product selection state. Initialization emits only the final settled state. Recommitting the same state does not emit again. Simple products do not emit it. |
| Detail payload | { product_id, selection: { phase, attributes }, selected_variation, current_product } |
selection.phase is base, partial, resolved, or invalid. selected_variation is the complete resolved variation object or null. current_product is the complete base product until resolution succeeds, then the complete resolved variation. Availability remains a field of the product or variation object; it is not encoded in the phase.
document.addEventListener("ome-woo:variation-selection-changed", (event) => {
const detail = (event as CustomEvent).detail;
if (detail.selection.phase === "resolved") {
console.log(detail.selected_variation);
}
});
Product Add Events
ome-woo:item-added
| Contract | Value |
|---|---|
| Dispatch target | The standalone AddToCartButton, or the submitted AddToCartForm for form-submit buttons. |
| Bubbles | Yes. |
| When it fires | After Store API POST /cart/add-item succeeds and the runtime has a fresh cart summary. |
| Detail payload | { product_id, quantity, cart_summary: { item_count, line_count }, variation_id?, variation?, price? } |
Use this event when the integration needs the product and quantity that were just added.
The analytics fields are additive and degrade gracefully:
variation_idis the variation that was actually added, ornullfor simple products.variationmaps variation attribute slugs to the selected value (for example{ "pa_size": "large" }).priceis the unit price of the added line:{ value, currency_code, currency_minor_unit }wherevalueis in minor units (for example grosze). It is present when the add-item response carries the line's price and currency.
ome-woo:cart-updated
| Contract | Value |
|---|---|
| Dispatch target | The same element that dispatched the successful cart mutation event. |
| Bubbles | Yes. |
| When it fires | After add-to-cart, quantity update, or item removal succeeds. |
| Detail payload | { cart_summary: { item_count, line_count } } |
Use this event when the integration only needs the latest cart count or line count.
Cart mutation scheduling is intentionally not a public event stream. There is no generic transaction-lifecycle event. For local visual progress, style data-ome-woo-mutation-phase; for business integrations, keep using the semantic events above.
ome-woo:add-to-cart-error
| Contract | Value |
|---|---|
| Dispatch target | The standalone AddToCartButton, or the submitted AddToCartForm for form-submit buttons. |
| Bubbles | Yes. |
| When it fires | After Store API POST /cart/add-item fails. |
| Detail payload | { product_id, quantity, error: { code, message, status, field_keys? } } |
Standard Analytics Bridge Events
OME dispatches the events analytics plugins already listen for, so GA4 and friends receive add_to_cart / remove_from_cart without custom code:
| Event | Dispatch target | When it fires | Detail |
|---|---|---|---|
wc-blocks_added_to_cart | document.body | After a successful add-to-cart. | { preserveCartData: true } |
wc-blocks_removed_from_cart | document.body | After a successful item removal. | { preserveCartData: true } |
jQuery added_to_cart | document.body (via jQuery(document.body).trigger) | After a successful add-to-cart, only when window.jQuery exists. | [fragments, cart_hash, $button] |
jQuery removed_from_cart | document.body (via jQuery(document.body).trigger) | After a successful item removal, only when window.jQuery exists. | [fragments, cart_hash] |
Notes:
- The
wc-blocks_*events follow the WooCommerce Blocks contract:bubbles: true,cancelable: true,detail: { preserveCartData: true }. Like Woo Blocks itself, they carry no product payload — useome-woo:item-addedfor product data. - The jQuery bridge is a strict no-op on jQuery-less sites (common with Etch); the DOM events above always fire.
Purchase Event
ome-woo:purchase
| Contract | Value |
|---|---|
| Dispatch target | document.body. |
| Bubbles | Yes. |
| When it fires | Once at Woo runtime boot on the order-received (thank-you) page, when an authorized order is present. |
| Detail payload | { order } |
This is the most robust purchase signal: it works across payment redirects and gateways because it fires on the thank-you page, and it carries everything a purchase event needs — without customer PII beyond order identifiers.
type WooPurchaseItem = {
product_id: number;
variation_id: number | null;
name: string;
quantity: number;
price: number; // unit price, major units
total: number; // line total, major units
};
type WooPurchaseOrder = {
id: number;
number: string;
status: string;
currency: string;
subtotal?: number;
shipping?: number;
tax?: number;
discount?: number;
total: number;
coupons?: string[];
items: WooPurchaseItem[];
};
Cart Item Events
ome-woo:cart-loaded
| Contract | Value |
|---|---|
| Dispatch target | First matching cart display root: [data-ome-woo-cart-count], [data-ome-woo-cart-total-field], [data-ome-woo-cart-items], [data-ome-woo-cart-notices], or document.body. |
| Bubbles | Yes. |
| When it fires | After Woo cart boot loads and cart display components are bound. |
| Detail payload | { cart_summary: { item_count, line_count } } |
ome-woo:item-quantity-updated
| Contract | Value |
|---|---|
| Dispatch target | The cart item quantity input. |
| Bubbles | Yes. |
| When it fires | After each real Store API quantity response is committed. Debounced-away, cancelled, and already-satisfied no-op targets do not emit it. An intermediate response still emits this semantic event, while control-local success waits for the latest target. |
| Detail payload | { key, quantity, cart_summary: { item_count, line_count } } |
ome-woo:item-removed
| Contract | Value |
|---|---|
| Dispatch target | The cart item remove button. If that button was detached before the request finished, the event is dispatched from document.body. |
| Bubbles | Yes. |
| When it fires | After Store API POST /cart/remove-item succeeds. |
| Detail payload | { key, cart_summary: { item_count, line_count } } |
ome-woo:cart-error
| Contract | Value |
|---|---|
| Dispatch target | The cart item quantity input for quantity failures, or the remove button for removal failures. |
| Bubbles | Yes. |
| When it fires | After Store API quantity update or item removal fails. |
| Detail payload | { action, key, quantity?, error: { code, message, status, field_keys? } }, where action is "update-item" or "remove-item". |
Checkout Events
ome-woo:checkout-loaded
| Contract | Value |
|---|---|
| Dispatch target | First matching checkout root: [data-ome-woo-checkout-provider], form[data-ome-woo-checkout-form], [data-ome-woo-checkout-notices], or document.body. |
| Bubbles | Yes. |
| When it fires | After checkout boot loads and checkout components are bound. |
| Detail payload | { checkout } |
ome-woo:checkout-started
| Contract | Value |
|---|---|
| Dispatch target | The checkout form. |
| Bubbles | Yes. |
| When it fires | After local submit validation passes and before payment preparation or Store API checkout submission. |
| Detail payload | {} |
ome-woo:checkout-complete
| Contract | Value |
|---|---|
| Dispatch target | The checkout form. |
| Bubbles | Yes. |
| When it fires | After Store API checkout succeeds. Redirect handling can happen after this event. |
| Detail payload | { checkout } |
ome-woo:checkout-error
| Contract | Value |
|---|---|
| Dispatch target | The checkout form. |
| Bubbles | Yes. |
| When it fires | After local validation, payment preparation, payment result handling, or Store API checkout fails. |
| Detail payload | Local validation: { errors, phase, source: "local-validation" }. Runtime/payment failure: { error, diagnostic? }. |
errors is an array of checkout field errors:
type WooCheckoutFieldError = {
field_key: string;
code: "required" | "invalid_email" | "invalid_country" | "invalid_state";
message: string;
};
phase is "submit" or "update". source is currently "local-validation" when the checkout form blocks submission before Store API checkout.
Example: Open A Mini-Cart Drawer After Add To Cart
Author the drawer and trigger normally:
<OmeDrawerTrigger
targeting='{{"targetDrawerId":"store-mini-cart"}}'
content='{{"label":"Cart"}}'
/>
<OmeDrawer
identity='{{"drawerId":"store-mini-cart"}}'
settings='{{"direction":"right","dismissible":true}}'
>
{#slot default}
<OmeDrawerTitle>Shopping bag</OmeDrawerTitle>
<OmeWooCartItems>
{#slot default}
<OmeWooCartItemImage />
<OmeWooCartItemTitle />
<OmeWooCartItemQuantity />
<OmeWooCartItemRemove />
{/slot}
{#slot empty}
Your cart is empty.
{/slot}
</OmeWooCartItems>
<OmeWooCartTotalsList />
<OmeDrawerClose>Close</OmeDrawerClose>
{/slot}
</OmeDrawer>
Then click the real trigger when ome-woo:item-added bubbles:
document.addEventListener("ome-woo:item-added", () => {
const trigger = document.querySelector(
'[data-ome-drawer-trigger][data-ome-target-drawer-id="store-mini-cart"]',
);
if (trigger instanceof HTMLButtonElement) {
trigger.click();
}
});
This keeps OmeDrawerTrigger and OmeDrawer as the drawer owners. The Woo event only decides when to open it.
Example: Track Add-To-Cart Analytics
document.addEventListener("ome-woo:item-added", (event) => {
if (!(event instanceof CustomEvent)) {
return;
}
const { product_id, quantity, variation_id, variation, price, cart_summary } = event.detail;
window.dataLayer?.push({
event: "add_to_cart",
ecommerce: {
currency: price?.currency_code,
value: price ? (price.value / 10 ** price.currency_minor_unit) * quantity : undefined,
items: [
{
item_id: variation_id ?? product_id,
item_name: undefined, // enrich from your own product feed if needed
quantity,
...(variation ? { item_variant: Object.values(variation).join(", ") } : {}),
...(price ? { price: price.value / 10 ** price.currency_minor_unit } : {}),
},
],
},
cart_items: cart_summary.item_count,
});
});
If you only need the conversion signal, prefer the automatic bridges above — most GA4 plugins pick up wc-blocks_added_to_cart or the jQuery added_to_cart event on their own.
document.addEventListener("ome-woo:item-removed", (event) => {
if (!(event instanceof CustomEvent)) {
return;
}
window.dataLayer?.push({ event: "remove_from_cart" });
});
document.addEventListener("ome-woo:purchase", (event) => {
if (!(event instanceof CustomEvent)) {
return;
}
const { order } = event.detail;
window.dataLayer?.push({
event: "purchase",
ecommerce: {
transaction_id: order.number,
currency: order.currency,
value: order.total,
tax: order.tax,
shipping: order.shipping,
coupon: order.coupons?.join(","),
items: order.items.map((item) => ({
item_id: item.variation_id ?? item.product_id,
item_name: item.name,
quantity: item.quantity,
price: item.price,
})),
},
});
});
Use ome-woo:purchase here because the thank-you page is the most reliable purchase surface: it fires across payment redirects and gateways. Use order.number as transaction_id so GA4 deduplicates reloads.
Example: Refresh Cart Integrations
document.addEventListener("ome-woo:cart-updated", (event) => {
if (!(event instanceof CustomEvent)) {
return;
}
const { cart_summary } = event.detail;
document.documentElement.dataset.cartItems = String(cart_summary.item_count);
});
Use ome-woo:cart-updated when the integration does not care whether the cart changed because of add, quantity, or removal.
Example: Capture Checkout Errors
document.addEventListener("ome-woo:checkout-error", (event) => {
if (!(event instanceof CustomEvent)) {
return;
}
const { errors, error, diagnostic } = event.detail;
console.warn("Checkout failed", {
fieldErrors: errors,
error,
diagnostic,
});
});
Use this for logging, support tooling, or checkout instrumentation. Let CheckoutNotices remain responsible for visible customer messages.