Skip to main content

Bundle Hooks

Bundle hooks let you customize the behavior of Glood.AI bundles at key lifecycle points. There are five hooks available, each called at a specific stage of the bundle’s lifecycle.

Hook Lifecycle Flow

1. Configuration Phase

  • OnConfigLoad is called when bundle data is first loaded
    • Modify or enrich bundle configuration
    • Set up initial state

2. Rendering Phase

  • OnBundleRender transforms bundle data for the Liquid template
    • Map products with options and variants
    • Calculate pricing
    • Resolve translations

3. Interaction Phase

  • OnVariantChange handles variant selection changes
    • Update URL parameters
    • Trigger UI updates

4. Cart Operations Phase

  • OnAddToCart fires before the cart API request
    • Validate cart operations
    • Pre-cart UI updates
  • OnAddedToCart fires after successful cart addition
    • Post-cart confirmations
    • Analytics tracking

Available Hooks

1. OnConfigLoad

Purpose: Modify bundle data when it is first loaded, before any rendering occurs. Parameters: Returns: The modified (or unmodified) bundle object. Example:
Use Cases:
  • Filter products before rendering
  • Enrich bundle data with additional information
  • Override default configuration

2. OnBundleRender

Purpose: Transform raw bundle data into the format consumed by the Liquid template. This is the primary hook for controlling what gets rendered. Parameters: Returns: An object with products (array) and translations (object). Example:
Use Cases:
  • Custom product mapping and data transformation
  • Price calculation logic
  • Custom translation resolution
  • Adding computed fields to products

3. OnVariantChange

Purpose: Handle variant selection changes when a customer picks a different option. Parameters: Returns: void Example:
Use Cases:
  • Update URL query parameters
  • Trigger custom analytics events
  • Update external UI elements
  • Sync variant selection with other page components

4. OnAddToCart

Purpose: Called immediately when the add-to-cart button is clicked, before the cart API request is made. Parameters: Returns: void Example:
Use Cases:
  • Pre-cart validation
  • Loading state UI updates
  • Analytics event firing
  • Custom cart payload modifications

5. OnAddedToCart

Purpose: Called after a successful add-to-cart API response. Parameters: Returns: void Example:
Use Cases:
  • Show success notifications
  • Open mini-cart or cart drawer
  • Redirect to cart page
  • Fire conversion tracking events
  • Update cart count in header

Available Utilities

The utils object passed to each hook provides these functions:

Support

If you need help with creating or customizing bundle hooks, contact our support team at support@glood.ai