Skip to content
On this page

Watcher Plugin

The widget may not always appear the first time a user adds an item to their cart, or it may disappear or display incorrect pricing when the user updates the quantity. This is where the Watcher Plugin comes in handy. It ensures that the widget is always visible and accurately reflects the current cart state, even during these edge cases.

Implementation Example

Go to the theme.liquid file where you initialized the widget and paste this observer code underneath.

<script defer>
  const widget = OrderProtection.createOrderProtectionWidget();

  const observer = new OrderProtection.Plugins.WatchChangesPlugin(
      callback: function () {
      element: document.querySelector("#cart-drawer"),

The WatchChangesPlugin accepts an object that includes a callback function to execute when changes are detected in the specified element. In this case, the element being monitored is document.querySelector("#cart-drawer"). When this element changes it will reinitialize the widget.