Skip to main content

Initialize Checkout Session with Items

Learn how to programmatically create a new checkout session with line items using the init() function from useCheckout().
Use Case: This is useful when you want to create a checkout without a pre-existing checkoutToken, such as:
  • Landing pages that add products directly to checkout
  • BOGO funnels that start with a specific bundle
  • Custom product selectors that initialize checkout on-the-fly

Basic Example


Complete Example with Store ID


With Static Resources (CRM-Configured Variants)

This example shows how to use variant IDs from funnel static resources:
In your plugin manifest, declare static resources:
Then merchants can configure which variant to use in the CRM Funnel Builder.

Multiple Line Items


With Specific Price ID (Subscription)


Key Points

Use init() when:
  • ✅ No checkoutToken is provided in the URL
  • ✅ You want to programmatically create a checkout
  • ✅ Building a landing page that adds products to cart
  • ✅ Creating custom bundle selectors
Don’t use init() when:
  • ❌ You have a checkoutToken from the URL
  • ❌ The checkout already exists (checkout data loaded)
Always use a ref to prevent multiple init calls:
Make sure to wait for:
  1. Funnel to be initialized (isInitialized)
  2. Context to be available (context)
  3. Static resources to load (if using them)
Always handle initialization errors:

API Reference

init() Parameters

Returns


Common Patterns

Pattern 1: Auto-initialize with Default Product

Pattern 2: Initialize from Static Resources

Pattern 3: Initialize with User Selection


Next Steps

Update Line Items

Learn how to update items after initialization

Process Payment

Process payment after checkout is ready

Static Resources

Use CRM-configured resources

Complete Example

See full checkout implementations