addEnrollmentPack()
Adds an enrollment pack to the cart, optionally with bundle selections for products in the pack that are dynamic bundles.
Signature
await window.FairShareSDK.addEnrollmentPack(enrollmentPackId, options);
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
enrollmentPackId | number | Yes | The enrollment pack ID |
options.event | EventType | No | Custom event type to dispatch (default: ADD_TO_CART) |
options.bundleSelections | BundleSelection[] | No | Bundle selections for dynamic bundle products in the pack |
BundleSelection Object:
| Property | Type | Required | Description |
|---|---|---|---|
variant_id | number | Yes | Variant ID of the enrollment pack product to attach bundle selections to |
bundled_items | BundledItem[] | No | Bundle group item selections for this product |
BundledItem Object:
| Property | Type | Required | Description |
|---|---|---|---|
variant_id | number | Yes | Variant ID of the bundled item |
quantity | number | Yes | Quantity of the bundled item (min: 0) |
display_to_customer | boolean | No | Whether to display bundled item to customer |
subscription | boolean | No | Whether bundled item is a subscription |
subscription_plan_id | number | null | No | Subscription plan ID for the bundled item |
Returns
Promise<Cart | undefined>
Examples
Simple Enrollment Pack
await window.FairShareSDK.addEnrollmentPack(539);
Enrollment Pack with Bundle Selections
await window.FairShareSDK.addEnrollmentPack(539, { bundleSelections: [ { variant_id: 278318, bundled_items: [ { variant_id: 39325, quantity: 1 }, { variant_id: 35376, quantity: 1 }, { variant_id: 11311, quantity: 1 }, ] } ] });
HTML Alternative
Use data attributes without JavaScript:
<!-- Basic enrollment pack --> <button data-fluid-add-enrollment-pack="539"> Add Enrollment Pack </button> <!-- Enrollment pack with bundle selections --> <button data-fluid-add-enrollment-pack="539" data-fluid-bundle-selections='[{"variant_id":278318,"bundled_items":[{"variant_id":39325,"quantity":1},{"variant_id":35376,"quantity":1},{"variant_id":11311,"quantity":1}]}]' > Add Enrollment Pack </button> <!-- Open cart after adding --> <button data-fluid-add-enrollment-pack="42" data-fluid-open-cart-after-add="true" > Add Enrollment Pack and View </button> <!-- Combined: Enrollment Pack + Items. --> <!-- data-fluid-add-combined="enrollment pack id + variant id 1, variant id 2" Expected: 'enrollmentPackId+variantId1,variantId2" --> <button data-fluid-add-combined="42+123456,789012"> Add Pack + Items </button>
Data Attributes
| Attribute | Type | Description |
|---|---|---|
data-fluid-add-enrollment-pack | string | Enrollment pack ID |
data-fluid-bundle-selections | JSON string | Array of { variant_id, bundled_items } for enrollment pack bundles |
data-fluid-open-cart-after-add | string | Set to "false" to prevent cart from opening |
Related
- addCartItems — Add regular items