Volume selector element
Updated Sep 18, 20264 min read
On this page (9)
<hype-volume-selector> renders a Volume Discount campaign as an interactive tier picker on the product page. The shopper chooses a tier, picks a variant for each item in it, and adds the whole tier to the cart in one action. It can add to the cart with its own button, or take over the theme's Add to cart button.
Placement
The theme editor block is Hype: Volume Selector. Place it inside the product form, near the Add to cart button. Two behaviors depend on that: the element finds the theme's submit button by walking up to the closest <form>, and it keeps itself in sync with the theme's quantity input.
<hype-volume-selector id="hype-volume" identifier="YOUR_APP_BLOCK_ID" {% if request.design_mode %}design-mode="true"{% endif %}></hype-volume-selector>Attributes
| Attribute | Required | Default | Description |
|---|---|---|---|
identifier | Yes | "" | The campaign block's App block ID |
design-mode | No | false | true renders placeholder tiers for styling in the theme editor |
override-add-to-cart | No | absent | When present, the element hides its own button and takes over the theme's Add to cart button |
add-to-cart-selector | No | — | CSS selector for the theme's Add to cart button. Only used with override-add-to-cart. |
override-add-to-cart is detected by presence, not by value. override-add-to-cart="false" still turns the override on — remove the attribute instead.
Standalone mode
This is the default. The element renders its own button, exposed as the custom-add-to-cart part, with the label Add to Cart. The button is disabled until the shopper selects a tier. Clicking it adds every item in the selected tier and dispatches hype:item-added-to-cart on document.
Use this when your theme's own button should keep working normally for single-unit purchases, or when the element sits outside the product form.
Overriding the theme's Add to cart button
Add override-add-to-cart and the element stops rendering its own button. Instead it attaches a click handler to the theme's button. When a tier is selected the handler cancels the theme's submit and adds the tier's items; when no tier is selected the theme's button behaves exactly as it did before.
<hype-volume-selector identifier="YOUR_APP_BLOCK_ID" override-add-to-cart="true" add-to-cart-selector=".product-form__submit"></hype-volume-selector>The element looks for the button in this order and stops at the first hit:
add-to-cart-selector, matched against the whole document.- The first
button[type="submit"]inside the closest ancestor<form>. - The first
button[type="submit"]inside the element's parent element. - The
button[type="submit"]whose center is closest to the element on screen.
If your theme's Add to cart control is an <input type="submit">, an <a>, or a <button> with no type="submit", only step 1 can find it — pass add-to-cart-selector explicitly.
Quantity input
On load the element looks for the first input[name="quantity"] in the document and keeps it in step with the tier selection:
- Selecting a tier writes that tier's item count into the input and dispatches an
inputevent, so the theme picks up the change. - Changing the input selects the tier whose quantity band contains the new value, and adds or removes variant rows until the count matches.
Tiers with an amount-based condition rather than a quantity-based one are not auto-selected from the quantity input.
CSS custom properties
| Property | Default | Applies to |
|---|---|---|
--primary-color | #000 | Text, borders and selected states |
--secondary-color | #fff | Tier container background |
--font-size | 10 | Base size. Written as a bare number — the element multiplies it by 1px. |
--max-width | 100 | Outer width. Also a bare number, multiplied by 1%. |
--font-weight | bold | Tier titles and prices |
--font-size and --max-width are the two variables on this element that take a plain number. --font-size: 12px will break the layout; write --font-size: 12. Everything inside the element is sized in em, so changing that one number scales the whole block proportionally.
Parts
Layout
| Part | Element |
|---|---|
container | Outer wrapper |
header | Header row with icon and title |
body | The list of tiers |
Tier
| Part | Element |
|---|---|
tier-container | One tier, clickable |
tier-header-wrapper | Everything inside a tier |
tier-header | Selection and pricing row |
tier-selection | Radio and labels |
radio-button | The radio indicator |
tier-label-wrapper | Badge and label column |
tier-label | Tier title, for example "Buy 3" |
discount-badge | The tier's discount badge, when the block enables it |
tier-pricing | Price column |
original-price | Struck-through total, when the block enables it and the totals differ |
discounted-price | Discounted total |
popular-badge | The "most popular" badge, when the block sets one |
badge-icon | Icon inside that badge |
badge-text | Text inside that badge |
Variant selection and add to cart
| Part | Element |
|---|---|
variant-pickers-container | Appears when a tier with variants is selected |
variant-picker-group | One item's pickers |
variant-picker-label | The item's number |
variant-select | A <select> for one option |
add-variant-button-container | Wrapper around the add button |
add-variant-button | "+ Add Variant" |
remove-variant-button | Removes an item, shown from the second item onward |
custom-add-to-cart | The element's own button, standalone mode only |
When the shop configures an option as a swatch, that option renders as swatches instead of a <select>, and variant-select is not present for it.
Styling example
<style> #hype-volume { --primary-color: #1f2937; --secondary-color: #ffffff; --font-size: 12; --max-width: 100; --font-weight: 600; } #hype-volume::part(tier-container) { border-radius: 10px; } #hype-volume::part(popular-badge) { text-transform: uppercase; letter-spacing: 0.05em; } #hype-volume::part(original-price) { opacity: 0.55; } #hype-volume::part(custom-add-to-cart) { border-radius: 999px; text-transform: uppercase; }</style>Related
Was this article helpful?
Related articles
Still stuck?
Ask a follow-up and we'll see it came from “Volume selector element”.
Opens chat with your question and a link to this article.