[mailpoet_page]

/* EPO — WhatsApp narudzba */ (function(){ var WA = '381692075715'; var NL = String.fromCharCode(10);function formatMsg(cart){ var items = cart.items || []; if(!items.length) return null; var msg = 'Zdravo,' + NL + NL + 'zelim da porucim eterica ulja:' + NL + NL; items.forEach(function(it){ var eur = (parseInt((it.prices && it.prices.price) || 0) / 100).toFixed(2).replace('.',','); msg += '- ' + it.name + ', kom: ' + it.quantity + ', cena: ' + eur + ' EUR' + NL; }); var tot = (parseInt((cart.totals && cart.totals.total_price) || 0) / 100).toFixed(2).replace('.',','); msg += NL + 'Ukupno: ' + tot + ' EUR' + NL + NL + 'Molim vas kontaktirajte me zbog dostave. Hvala!'; return msg; }function openWA(e){ if(e){ e.preventDefault(); e.stopImmediatePropagation(); } fetch('/wp-json/wc/store/v1/cart', {credentials:'include'}) .then(function(r){ return r.json(); }) .then(function(cart){ var msg = formatMsg(cart); window.open('https://wa.me/' + WA + (msg ? '?text=' + encodeURIComponent(msg) : ''), '_blank'); }) .catch(function(){ window.open('https://wa.me/' + WA, '_blank'); }); }function hookLinks(){ document.querySelectorAll('a[href*="shop.html"]').forEach(function(a){ if(a.dataset.waHooked) return; a.dataset.waHooked = '1'; a.removeAttribute('href'); a.style.cursor = 'pointer'; a.addEventListener('click', openWA); }); }document.addEventListener('click', function(e){ var link = e.target.closest('a[href*="shop.html"]'); if(link){ openWA(e); } }, true);hookLinks(); var scanInterval = setInterval(hookLinks, 500); setTimeout(function(){ clearInterval(scanInterval); }, 30000); new MutationObserver(hookLinks).observe(document.body, {childList:true, subtree:true});})();