/* --------------------------- 6) PRO+ Pills -> Woo variation select sync ---------------------------- */ (function initVariationPills() { const pillsWrap = document.querySelector("[data-mo-pills]"); if (!pillsWrap) return; const attrName = pillsWrap.getAttribute("data-attr-name"); if (!attrName) return; const form = document.querySelector("form.variations_form"); if (!form) return; const select = form.querySelector('select[name="'+attrName+'"]'); if (!select) return; const pills = pillsWrap.querySelectorAll(".mo-sp-pill"); const setActive = (val)=>{ pills.forEach(p=>{ const a = p.getAttribute("data-attr-value"); p.classList.toggle("is-active", a===val); }); }; pills.forEach(btn=>{ btn.addEventListener("click", function(){ const val = this.getAttribute("data-attr-value"); if(!val) return; select.value = val; if(window.jQuery){ const $ = window.jQuery; $(select).trigger("change"); $(form).trigger("woocommerce_variation_select_change"); $(form).trigger("check_variations"); $(form).trigger("found_variation"); } setActive(val); }); }); if(select.value) setActive(select.value); })();