Sepetiniz şu anda boş!
Mağazada yeni
(function() {
var PHONE = ‘905324412355’;
function buildMessage() {
return fetch(‘/wp-json/wc/store/v1/cart’, { credentials: ‘same-origin’ })
.then(function(r) { return r.json(); })
.then(function(cart) {
var message = ‘Merhaba! Aşağıdaki siparişi vermek istiyorum:\n\n’;
if (cart.items && cart.items.length > 0) {
cart.items.forEach(function(item) {
var name = item.name || item.title || ”;
message += ‘🎂 ‘ + name + ‘\n’;
message += ‘ Adet: ‘ + item.quantity + ‘\n’;
var price = item.totals && item.totals.line_total
? (parseInt(item.totals.line_total) / 100).toFixed(2) + ‘ TL’
: ”;
if (price) message += ‘ Fiyat: ‘ + price + ‘\n’;
message += ‘\n’;
});
var total = cart.totals && cart.totals.total_price
? (parseInt(cart.totals.total_price) / 100).toFixed(2) + ‘ TL’
: ”;
if (total) message += ‘Toplam: ‘ + total + ‘\n’;
}
message += ‘\nBu siparişi vermek istiyorum.’;
return message;
})
.catch(function() {
return ‘Merhaba! Sipariş vermek istiyorum.’;
});
}
function goWhatsApp(e) {
e.preventDefault();
e.stopImmediatePropagation();
buildMessage().then(function(msg) {
window.open(‘
https://wa.me/’ + PHONE + ‘?text=’ + encodeURIComponent(msg), ‘_blank’);
});
return false;
}
function hookButtons() {
var selectors = [
‘.wc-block-cart__submit-button’,
‘.wp-block-woocommerce-proceed-to-checkout-block a’,
‘.wp-block-woocommerce-proceed-to-checkout-block button’,
‘.wc-block-cart__submit a’,
‘.wc-block-cart__submit button’,
‘.checkout-button’,
‘a[href*=”odeme”]’,
‘a[href*=”checkout”]’,
‘.wc-block-mini-cart__footer a’,
‘.wc-block-mini-cart__footer button’,
‘.wc-block-mini-cart__footer-actions a’,
‘.wc-block-mini-cart__footer-actions button’
];
selectors.forEach(function(sel) {
document.querySelectorAll(sel).forEach(function(btn) {
if (btn.dataset.waHooked) return;
btn.dataset.waHooked = ‘1’;
btn.addEventListener(‘click’, goWhatsApp, true);
});
});
}
document.addEventListener(‘DOMContentLoaded’, function() {
hookButtons();
var observer = new MutationObserver(hookButtons);
observer.observe(document.body, { childList: true, subtree: true });
setInterval(hookButtons, 500);
});
})();