Created
August 9, 2023 19:06
-
-
Save ihorduchenko/5b2850eb0b727a9ad993e587ab3981d3 to your computer and use it in GitHub Desktop.
Manipulate with checkout discount area using Shopify Checkout library + js modules assets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- comment -%} | |
https://www.npmjs.com/package/@adearriba/shopify-checkout?activeTab=code | |
{%- endcomment -%} | |
<script type="module" src="{{ 'shopify-checkout.js' | asset_url }}"></script> | |
<script> | |
import { $checkout } from './shopify-checkout.js'; | |
$checkout.on('load', (e) => { | |
console.log(e); | |
let discountNumberLineEl = document.querySelector('[data-checkout-discount-amount-target]'); | |
let discountTotalTargets = document.querySelectorAll('.discountTotal'); | |
if (discountTotalTargets) { | |
setTimeout(() => { | |
const discountSuccessMessageTarget1 = document.querySelector('.checkout-breadcrumbs'); | |
if (discountSuccessMessageTarget1 && ! discountSuccessMessageTarget1.querySelector('.discountSuccessMessageRoot')) { | |
discountSuccessMessageTarget1.appendChild(discountSuccessMessageRoot.cloneNode(true)); | |
} | |
handleDiscountSuccessMessage(discountNumberLineEl, discountTotalTargets); | |
}, 500); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment