Cart integration
When cart integration is enabled on a widget, customers can add products to their shopping cart directly from the visualization result screen. You implement the actual cart logic through callbacks.How it works
- The customer generates a visualization and sees the result
- They click Add to Cart in the widget
- The widget sends a
widget:add-to-cartmessage to your page - Your
onAddToCartcallback handles the cart operation - The widget shows a success or error state based on your response
Enabling cart integration
First, enable cart in the widget configuration in the dashboard. Then provide the callbacks when opening the widget:Callback reference
onAddToCart(product, quantity, variation)
Called when the customer clicks “Add to Cart” in the widget.
Parameters:
The product to add.
Number of items to add.
Selected product variations (for variable products).
Promise that resolves to one):
void or undefined, it’s treated as { success: true }.
onViewCart()
Called when the customer clicks “View Cart” after adding to cart. Navigate them to your cart page.
onCheckout()
Called when the customer clicks “Checkout” after adding to cart. Navigate them to your checkout page.
Examples
Simple REST API cart
WooCommerce AJAX cart
Shopify AJAX cart
Error handling
If you don’t provideonAddToCart but cart is enabled on the widget, the customer will see an error when they try to add to cart.
If your callback throws an error, the widget catches it and shows an error message to the customer.