` }, "Simple": { "selector": ".product-single__prices", "content": ` ()` }, "Minimal": { "selector": ".product-single__prices", "content": ` ()` }, "Supply": { "selector": "#comparePrice-product-template", "content": ` ()` }, "Boundless": { "selector": ".product__price", "content": ` ()` }, }; window.addEventListener('load', (event) => { let selected = 31879745503363; let rules = ; const urlParams = new URLSearchParams(window.location.search); let myParam = urlParams.get('variant') ? parseInt(urlParams.get('variant')) : selected; let res = rules.filter(ele => ele._variant_id === parseInt(myParam)); appendInput(res, myParam) let firstTimeUrl = document.URL; document.addEventListener('change', function() { let currentPageUrl = document.URL; let url = new URL(currentPageUrl); let isVariantUrl = parseInt(url.searchParams.get("variant")); if (myParam !== isVariantUrl) { myParam = isVariantUrl let res = rules.filter(ele => ele._variant_id === parseInt(myParam)); if (document.getElementById('campaign')) document.getElementById('campaign').remove() if (document.getElementById('origprice')) document.getElementById('origprice').remove() if (document.getElementById('rule')) document.getElementById('rule').remove() appendInput(res, isVariantUrl) } }); }); function appendInput(res, variantId) { const isCheckoutLabel = false; if (document.getElementById('showDiscount')) document.getElementById('showDiscount').remove() if (res.length > 0) { res.forEach(ele => { let orig_price = parseInt(ele._origprice) let input = ` ` input += ` ` input += ` ` var div = document.querySelector('[name="form_type"]'); div.innerHTML += input // const title = isCheckoutLabel ? `${ele._campaign} ${ele._discount}` : ele._discount; // showDiscount(title) }) } } function showDiscount(title){ const theme = Shopify.theme.name; const themeObj = showDiscountObj[theme] const selector = themeObj.selector; let content = themeObj.content; content = content.replace("", title) document.querySelector(selector).innerHTML += content; }