Addons

Live Purchase Toast

Shows rotating “Someone just purchased…” toasts using recent orders fetched from Order::recentWithItems(). Ideal for lightweight social proof on landing and product pages.

How it works

  • The addon registers via LivePurchaseToastAddon and injects hooks on wp_enqueue_scripts + wp_footer.
  • AddonRegistry::getSettings('live_purchase_toast') provides the message template (defaults to “Someone in {location} purchased”).
  • Order::recentWithItems(12) supplies payloads (product name, slug, featured image, and customer location parsed from the shipping address).
  • Assets: live-purchase-toast.css and live-purchase-toast.js render a floating stack of toasts with entry/exit animations.

Settings reference

Field Key Description
Message Template message_template Text shown above the product title. Supports the {location} token; fallback location is “your area”.

Settings are saved inline from the Addons list through AddonRegistry::updateSettings()—no extra save button.

Frontend behavior

  1. The script reads localized payloads from window.KitbixPurchaseToast (injected when at least one order exists).
  2. A container <div data-kitbix-purchase-toast> is printed in the footer.
  3. Every 11 seconds the JS selects the next payload, renders image + message, and auto-dismisses the toast after ~5 seconds.
  4. Clicking a toast with a product slug navigates shoppers to kitbix_commerce_product_permalink().
Tip: Seed at least one manual test order per product so social proof looks real on launch day.

Testing checklist

  • Enable the addon in Kitbix Commerce → Addons and enter a localized message template.
  • Create a few orders with different cities to ensure the {location} token resolves cleanly.
  • Visit pages containing [kitbix_commerce_products], product, cart, or checkout shortcodes—the assets load whenever storefront pages are detected.
  • Confirm toasts rotate, fade out, and link correctly (inspect live-purchase-toast.js errors if they do not).

Common pitfalls

  • Empty orders table → no payload → no assets enqueued. Run a staging order to populate data.
  • Long message templates wrapping onto multiple lines; keep them under ~60 characters.
  • Disabled addon toggled by automation. Use AddonRegistry::isEnabled('live_purchase_toast') to verify state when debugging.
Reminder: This addon only reads recent orders—if you delete orders in wp-admin, the toast queue clears until new sales arrive.