<script>
(function(){
const TAG = 'enquire-only'; // product tag to trigger
const ENQUIRE_URL = '/contact'; // or 'mailto:admin@elisab.com.au'
const ENQUIRE_TEXT = 'ENQUIRE NOW';
function hasTag(prod){
const tagLinks = prod.querySelectorAll('.ProductItem-tags a, .ProductMeta-tags a');
if ([...tagLinks].some(a => (a.textContent||'').trim().toLowerCase() === TAG)) return true;
// fallback: JSON-LD keywords (if template hides tags)
try {
const ld = document.querySelector('script[type="application/ld+json"]');
if (ld) {
const data = JSON.parse(ld.textContent);
const kws = (data.keywords || '').toLowerCase().split(',').map(s=>s.trim());
if (kws.includes(TAG)) return true;
}
} catch(e){}
return false;
}
// Turn the Add to Cart button into a link
function replaceATC(prod){
if (prod.classList.contains('enquire-only')) return;
prod.classList.add('enquire-only');
const btn = prod.querySelector('.sqs-add-to-cart-button');
if (!btn) return;
// Build destination with product name as a query param
const title = (prod.querySelector('.ProductItem-details .ProductItem-title')?.textContent || '').trim();
const dest = ENQUIRE_URL.startsWith('mailto:')
? ENQUIRE_URL
: ENQUIRE_URL + (title ? (`?subject=${encodeURIComponent('Enquiry: ' + title)}`) : '');
// Convert button behaviour
btn.textContent = ENQUIRE_TEXT;
btn.setAttribute('href', dest);
btn.setAttribute('type',''); // not a submit anymore
btn.onclick = null;
// If it is a <button>, swap to <a> for clean navigation
if (btn.tagName.toLowerCase() === 'button') {
const a = document.createElement('a');
[...btn.attributes].forEach(attr => a.setAttribute(attr.name, attr.value));
a.className = btn.className;
a.textContent = ENQUIRE_TEXT;
a.href = dest;
btn.replaceWith(a);
}
// Create a holder right under the button for the accordions
const holder = document.createElement('div');
holder.className = 'enquiry-accordion-wrap';
const anchor = prod.querySelector('.sqs-add-to-cart-button, .enquire-now-btn, .ProductItem .sqs-add-to-cart-button');
(anchor || prod).insertAdjacentElement('afterend', holder);
// Move any accordion blocks on the page into the holder (keeps content exactly as you made it)
const accs = prod.querySelectorAll('.sqs-block-accordion');
accs.forEach(acc => holder.appendChild(acc));
}
function run(){
document.querySelectorAll('.ProductItem').forEach(prod=>{
if (hasTag(prod)) replaceATC(prod);
});
// Quick View modal
document.querySelectorAll('.sqs-quick-view-lightbox .ProductItem').forEach(prod=>{
if (hasTag(prod)) replaceATC(prod);
});
}
document.addEventListener('DOMContentLoaded', run);
document.addEventListener('ajaxload', run);
})();
</script>