LindsayKB
2/2/2022 - 1:09 AM

Redirect User to Shopify's Checkout or Third-Party Checkout Platform Based on Location

<form action="/checkout" style="display: none;">
    <a href="/checkout" name="checkout" style="display: none;"></a>
</form>
<button id="buy_now_button">BUY NOW</button>
var buyNow = document.getElementById('buy_now_button');
buyNow && buyNow.addEventListener('click', function (evt) {
    evt.preventDefault();
    $.get("http://ipinfo.io", function (response) {
        if (response.country == "US") {
            //Send to CartHook
            window.testGlobalBeforeReact(0);
        }
        else if (response.country != "US") {
            //Send to Shopify
            window.location.href ='/checkout';
        }
    }, "jsonp");
});