Skip to main content

WordPress · Cart bridge

The cart bridge keeps the widget in sync with the WooCommerce cart. When a customer adds, removes or empties the cart, the plugin emits a CustomEvent('neuroon:cart-update') on window. The widget listens for that event and refreshes its responses (cross-sell, validations, prompts).

You do not have to do anything to enable the bridge: the plugin wires it up automatically when it loads the widget on the page. Internally measured coverage: ~95 % of cart mutations on a standard WC.

Event name

The plugin listens for WooCommerce cart changes (add, remove, empty) and, when it detects a mutation, dispatches CustomEvent('neuroon:cart-update') on window. This is the same event name documented in the recipes/custom-cart-bridge recipe, so any listener you write works the same whether you use the plugin or your own integration.

Payload

The plugin emits the event without payload (detail absent). The widget asks the server for the updated cart state through the WooCommerce AJAX API (fragments) or queries the public WC endpoint directly. This avoids exposing sensitive data from inline scripts.

If you have a special case (cart in custom JSON, headless WC, etc.), you can emit your own event with detail:

window.dispatchEvent(new CustomEvent('neuroon:cart-update', {
detail: {
items: [
{ productId: 'PRD-001', name: 'Smart Speaker', price: 79.99, quantity: 2 }
],
total: 159.98,
currency: 'EUR'
}
}));

The widget accepts both modes.

Validate that the bridge works

  1. Open the browser console on a product page.
  2. Subscribe:
window.addEventListener('neuroon:cart-update', e => console.log('cart-update', e));
  1. Click Add to cart. You should see the log almost instantly.

If you do not see the event:

  • Check that jQuery is loaded (typeof jQuery !== 'undefined' in console).
  • Verify that the widget is active on the page (its configuration block should have been printed).
  • Look at the plugin's Diagnostics tab to see whether the bridge is marked as attached.

When NOT to use this bridge

  • Headless WooCommerce / custom storefront: your own frontend already knows the cart state; emit your own CustomEvent directly. See recipes/custom-cart-bridge.
  • Fully external AJAX carts (e.g. mini-cart built in React mounted outside WC): same as above, dispatch yourself.

Next steps