Skip to content
document.addEventListener("DOMContentLoaded", function () {
// Only run this on the mini fun package product page
if (!window.location.pathname.includes('/product/mini-fun-package')) return;
const MAX_FLAVORS = {
'50': 3,
'100': 5
// 125+ or others will allow all 7
};
const REACHED_LIMIT_OPTION = "reached-flavor-limit"; // Value in option list
function updateFlavorFields(servingSize) {
const maxFlavors = MAX_FLAVORS[servingSize] || 7;
for (let i = 1; i <= 7; i++) {
const flavorAttr = i === 1 ? 'flavor1' : `flavor-${i}`;
const select = document.querySelector(`select[name="attribute_pa_${flavorAttr}"]`);
if (select) {
if (i <= maxFlavors) {
select.disabled = false;
select.parentElement.style.display = 'block';
} else {
// Set to "Reached flavor limit"
const optionToSelect = Array.from(select.options).find(opt => opt.value === REACHED_LIMIT_OPTION);
if (optionToSelect) {
select.value = REACHED_LIMIT_OPTION;
select.dispatchEvent(new Event('change', { bubbles: true }));
}
select.disabled = false;
select.parentElement.style.display = 'none';
}
}
}
}
const servesSelect = document.querySelector('select[name="attribute_pa_serves"]');
if (servesSelect) {
servesSelect.addEventListener('change', function () {
updateFlavorFields(this.value);
});
updateFlavorFields(servesSelect.value); // Run on load
}
});