DEV Community

Cover image for Custom Build-a-Box Subscription Flow in Shopify.
Peter Aderinto
Peter Aderinto

Posted on

Custom Build-a-Box Subscription Flow in Shopify.

Custom bundle and subscription builders are effective tools for increasing average order value, especially for wellness and personal care brands. However, the way these features are commonly implemented often hurts storefront speed. Many merchants install heavy third-party bundle apps that load external stylesheets, tracking scripts, and embedded iframes onto the product page. On mobile connections, that extra script weight delays page interactivity right when a customer is deciding what to buy.

While building custom features for a Scandinavian wellness brand, the main requirement was to let customers assemble a personalized subscription box with fixed item limits, live slot feedback, and recurring delivery options without relying on external apps. Keeping the entire flow inside Shopify's native Liquid templates and Ajax Cart API made it possible to deliver a fast, responsive experience while keeping catalog and inventory management simple for the store team.

The architecture relies on three native parts of the Shopify platform working together: First, all products eligible for the custom box are pulled from a dedicated Shopify collection using Liquid, which allows the merchant to add or remove box items directly from the admin panel. Each rendered item carries its variant ID, price, and default selling plan ID as HTML data attributes so JavaScript can read them without making extra API calls.


Second, a lightweight vanilla JavaScript controller manages the box capacity on the client side, tracking how many items a shopper has selected and enabling the checkout button only when the box is full. Instead of creating artificial bundle SKUs that complicate warehouse fulfillment, the script sends all selected variants to /cart/add.js in a single batch request:


`javascript
const items = selectedVariants.map((item, index) => ({
  id: item.id,
  quantity: 1,
  selling_plan: isSubscription ? item.sellingPlan : undefined,
  properties: {
    _box_group: boxGroupId,
    'Box Slot': `${index + 1} of ${capacity}`
  }
}));

await fetch(`${window.Shopify.routes.root}cart/add.js`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ items })
});`


Because each selected slot pushes a real variant ID to the cart, inventory counts deduct accurately at checkout without requiring background sync jobs. Prefixing the group property with an underscore (_box_group) keeps internal tracking IDs hidden on Shopify's checkout screen while still letting the theme's cart drawer group those items together visually. Removing third-party bundle widgets keeps interaction delays minimal on mobile devices, giving customers a smoother path from product selection to checkout.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)