30% off all compounds + up to 15% off bulk orders
', 'text/html'); var removed = false; doc.querySelectorAll('.fkcart-applied-coupon, .fkcart-coupon-tag, [class*="fkcart-applied-coupon"]') .forEach(function (pill) { var el = pill.querySelector('span, .fkcart-coupon-name, .fkcart-coupon-label'); var text = (el ? el.textContent : pill.textContent).trim(); log('pill text found:', text, '— isDr:', isDrCoupon(text)); if (testFn(text)) { pill.parentNode && pill.parentNode.removeChild(pill); removed = true; } }); doc.querySelectorAll('tr.cart-discount, .cart-discount').forEach(function (row) { var hit = false; Array.prototype.slice.call(row.classList).forEach(function (cls) { if (!hit && cls.indexOf('coupon-') === 0 && testFn(cls.replace('coupon-', ''))) hit = true; }); if (!hit) { var cell = row.querySelector('th, td'); if (cell) { log('row cell text:', cell.textContent.trim()); } if (cell && testFn(cell.textContent.trim())) hit = true; } if (hit) { row.parentNode && row.parentNode.removeChild(row); removed = true; } }); return removed ? doc.body.innerHTML : html; } function scrubDom() { var testFn = cfg.mode === 'disable_rules' ? isDrCoupon : isRealCoupon; document.querySelectorAll('.fkcart-applied-coupon, .fkcart-coupon-tag, [class*="fkcart-applied-coupon"]') .forEach(function (pill) { var el = pill.querySelector('span, .fkcart-coupon-name, .fkcart-coupon-label'); var text = (el ? el.textContent : pill.textContent).trim(); if (testFn(text)) { log('DOM: fading pill:', text); fadeRemove(pill); } }); document.querySelectorAll('tr.cart-discount, .cart-discount').forEach(function (row) { var hit = false; Array.prototype.slice.call(row.classList).forEach(function (cls) { if (!hit && cls.indexOf('coupon-') === 0 && testFn(cls.replace('coupon-', ''))) hit = true; }); if (!hit) { var cell = row.querySelector('th, td'); if (cell && testFn(cell.textContent.trim())) hit = true; } if (hit) { log('DOM: fading row'); fadeRemove(row); } }); } function fadeRemove(el) { el.style.transition = 'opacity 0.15s'; el.style.opacity = '0'; setTimeout(function () { if (el.parentNode) el.parentNode.removeChild(el); }, 160); } // ── MutationObserver fallback — scoped to .fkcart-modal only ───────────── function attachObserver() { var root = document.querySelector('.fkcart-modal, #fkcart-modal, [class*="fkcart-modal"]'); if (!root || root._fkdrObs) return; log('MutationObserver attached to', root.className); var obs = new MutationObserver(function (mutations) { if (!mutations.some(function (m) { return m.addedNodes.length > 0; })) return; if (!root._fkdrPending) { root._fkdrPending = true; requestAnimationFrame(function () { root._fkdrPending = false; scrubDom(); }); } }); obs.observe(root, { childList: true, subtree: true }); root._fkdrObs = obs; } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', attachObserver); } else { attachObserver(); setTimeout(attachObserver, 800); } document.addEventListener('fkcart:open', attachObserver); document.addEventListener('fkcart:ready', attachObserver); })(); (function () { 'use strict'; var cfg = window.fkdrFixConfig || { mode: 'both', drCouponPrefix: 'wdr_', debug: false }; function log() { if (cfg.debug) console.log('[FKDR]', Array.prototype.join.call(arguments, ' ')); } log('JS loaded — mode:', cfg.mode); if (cfg.mode === 'both') { log('mode=both, exiting'); return; } function isDrCoupon(code) { var c = (code || '').toLowerCase().trim(); if (cfg.drCouponPrefix && c.indexOf(cfg.drCouponPrefix) === 0) return true; return false; } function isRealCoupon(code) { return !isDrCoupon(code); } // ── XHR intercept ──────────────────────────────────────────────────────── var OriginalXHR = window.XMLHttpRequest; function PatchedXHR() { var xhr = new OriginalXHR(); var _isCouponOp = false; var _couponCode = ''; var origOpen = xhr.open.bind(xhr); var _openUrl = ''; xhr.open = function (method, url) { _openUrl = url || ''; return origOpen.apply(this, arguments); }; var origSend = xhr.send.bind(xhr); xhr.send = function (body) { var bodyStr = (body || '').toString(); // FK Cart uses wc-ajax URL param: ?wc-ajax=fkcart_apply_coupon // Coupon code is in POST body as discount_code= var isFkCartCoupon = _openUrl.indexOf('wc-ajax=fkcart_apply_coupon') !== -1; // Standard WC coupon apply as fallback var isStandardCoupon = ( bodyStr.indexOf('action=woocommerce_apply_coupon') !== -1 || bodyStr.indexOf('action=wfacp_apply_coupon') !== -1 || bodyStr.indexOf('action=wfocu_apply_coupon') !== -1 ); if (isFkCartCoupon || isStandardCoupon) { // FK Cart uses discount_code, WC core uses coupon_code var match = bodyStr.match(/discount_code=([^&]+)/) || bodyStr.match(/coupon_code=([^&]+)/); _couponCode = match ? decodeURIComponent(match[1]).toLowerCase().trim() : ''; _isCouponOp = true; log('XHR intercepted coupon apply — url:', _openUrl, 'code:', _couponCode); if (cfg.mode === 'disable_coupons' && isRealCoupon(_couponCode)) { log('mode=disable_coupons — aborting XHR send'); setTimeout(function () { document.body.dispatchEvent(new CustomEvent('wc_fragments_refreshed')); }, 50); return; } } return origSend.apply(this, arguments); }; xhr.addEventListener('load', function () { if (!_isCouponOp) return; log('XHR response received'); try { var parsed = JSON.parse(xhr.responseText); if (parsed && parsed.fragments) { var changed = false; Object.keys(parsed.fragments).forEach(function (key) { var html = parsed.fragments[key]; if (typeof html !== 'string') return; var testFn = cfg.mode === 'disable_rules' ? isDrCoupon : isRealCoupon; var scrubbed = scrubHtml(html, testFn); if (scrubbed !== html) { log('scrubbed fragment:', key); parsed.fragments[key] = scrubbed; changed = true; } }); if (changed) { var clean = JSON.stringify(parsed); Object.defineProperty(xhr, 'responseText', { get: function () { return clean; }, configurable: true }); Object.defineProperty(xhr, 'response', { get: function () { return clean; }, configurable: true }); log('response overwritten with clean fragments'); } else { log('no fragments needed scrubbing'); } } } catch (e) { log('parse error:', e.message); } requestAnimationFrame(scrubDom); }); return xhr; } PatchedXHR.prototype = OriginalXHR.prototype; Object.keys(OriginalXHR).forEach(function (k) { try { PatchedXHR[k] = OriginalXHR[k]; } catch(e){} }); window.XMLHttpRequest = PatchedXHR; // ── Scrubbers ───────────────────────────────────────────────────────────── function scrubHtml(html, testFn) { var doc = new DOMParser().parseFromString('' + html + '', 'text/html'); var removed = false; doc.querySelectorAll('.fkcart-applied-coupon, .fkcart-coupon-tag, [class*="fkcart-applied-coupon"]') .forEach(function (pill) { var el = pill.querySelector('span, .fkcart-coupon-name, .fkcart-coupon-label'); var text = (el ? el.textContent : pill.textContent).trim(); log('pill text found:', text, '— isDr:', isDrCoupon(text)); if (testFn(text)) { pill.parentNode && pill.parentNode.removeChild(pill); removed = true; } }); doc.querySelectorAll('tr.cart-discount, .cart-discount').forEach(function (row) { var hit = false; Array.prototype.slice.call(row.classList).forEach(function (cls) { if (!hit && cls.indexOf('coupon-') === 0 && testFn(cls.replace('coupon-', ''))) hit = true; }); if (!hit) { var cell = row.querySelector('th, td'); if (cell) { log('row cell text:', cell.textContent.trim()); } if (cell && testFn(cell.textContent.trim())) hit = true; } if (hit) { row.parentNode && row.parentNode.removeChild(row); removed = true; } }); return removed ? doc.body.innerHTML : html; } function scrubDom() { var testFn = cfg.mode === 'disable_rules' ? isDrCoupon : isRealCoupon; document.querySelectorAll('.fkcart-applied-coupon, .fkcart-coupon-tag, [class*="fkcart-applied-coupon"]') .forEach(function (pill) { var el = pill.querySelector('span, .fkcart-coupon-name, .fkcart-coupon-label'); var text = (el ? el.textContent : pill.textContent).trim(); if (testFn(text)) { log('DOM: fading pill:', text); fadeRemove(pill); } }); document.querySelectorAll('tr.cart-discount, .cart-discount').forEach(function (row) { var hit = false; Array.prototype.slice.call(row.classList).forEach(function (cls) { if (!hit && cls.indexOf('coupon-') === 0 && testFn(cls.replace('coupon-', ''))) hit = true; }); if (!hit) { var cell = row.querySelector('th, td'); if (cell && testFn(cell.textContent.trim())) hit = true; } if (hit) { log('DOM: fading row'); fadeRemove(row); } }); } function fadeRemove(el) { el.style.transition = 'opacity 0.15s'; el.style.opacity = '0'; setTimeout(function () { if (el.parentNode) el.parentNode.removeChild(el); }, 160); } // ── MutationObserver fallback — scoped to .fkcart-modal only ───────────── function attachObserver() { var root = document.querySelector('.fkcart-modal, #fkcart-modal, [class*="fkcart-modal"]'); if (!root || root._fkdrObs) return; log('MutationObserver attached to', root.className); var obs = new MutationObserver(function (mutations) { if (!mutations.some(function (m) { return m.addedNodes.length > 0; })) return; if (!root._fkdrPending) { root._fkdrPending = true; requestAnimationFrame(function () { root._fkdrPending = false; scrubDom(); }); } }); obs.observe(root, { childList: true, subtree: true }); root._fkdrObs = obs; } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', attachObserver); } else { attachObserver(); setTimeout(attachObserver, 800); } document.addEventListener('fkcart:open', attachObserver); document.addEventListener('fkcart:ready', attachObserver); })(); //# sourceURL=wc-cart-fragments-js-after