var buyNow = document.getElementById('buy_now_button');
buyNow && buyNow.addEventListener('click', function (evt) {
evt.preventDefault();
jQuery.getJSON('/cart.js', function(cart) {
// now have access to Shopify cart object
var source = "CartHook";
// loop through cart
for (i = 0; i < cart.items.length; i++) {
var currentID = cart.items[i].product_id;
//If current product ID matches the desired product ID, go to Shopify
if (currentID == "PRODUCT ID") {
source = "Shopify";
break;
}
}
console.log(source);
//If Product ID is not found, redirect to CartHook
if (source == "CartHook") {
window.testGlobalBeforeReact(0);
}
else if (source == "Shopify") {
window.location.href ='/checkout';
}
} );
});