Skip to content

Instantly share code, notes, and snippets.

@mkhizeryounas
Created March 18, 2020 21:32
Show Gist options
  • Save mkhizeryounas/737cd37391a5738d7c89f241ddfcb9e3 to your computer and use it in GitHub Desktop.
Save mkhizeryounas/737cd37391a5738d7c89f241ddfcb9e3 to your computer and use it in GitHub Desktop.
Order complete redirect script for headless shopify
<script>
let base_url = 'https://zarashahjahan.com';
let url = '';
try {
let order_id_sel = document.getElementsByClassName("os-order-number")
let orderid = order_id_sel.length ? order_id_sel[0].innerText.toLocaleLowerCase().replace("order", "").trim() : null
const mop =
document.getElementsByClassName('payment-method-list_item_info')
.length !== 0
? document.getElementsByClassName('payment-method-list_item_info')[0]
.innerText
: 'Cash on Delivery (COD)';
if (mop === 'Cash on Delivery (COD)') {
const obj = {
order_id: orderid || Shopify.checkout.order_id,
phone: Shopify.checkout.billing_address.phone
};
const stringifiedObj = btoa(JSON.stringify(obj));
url = `${base_url}/order-verification?data=${stringifiedObj}`;
} else {
url = `${base_url}/thank-you?id=${Shopify.checkout.order_id}`;
}
} catch (err) {
url = `${base_url}/thank-you`;
}
window.location.replace(url);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment