Skip to content

Instantly share code, notes, and snippets.

@blixxurd
Last active August 19, 2020 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blixxurd/020a68e2d11809fdd180d9597f7d7649 to your computer and use it in GitHub Desktop.
Save blixxurd/020a68e2d11809fdd180d9597f7d7649 to your computer and use it in GitHub Desktop.
// Our original Code
var variant = {{ current_variant | json }};
if (variant){
var fields = JSON.parse('{{ product.metafields.decify | json }}');
if(typeof fields[variant.id] !== 'undefined') {
console.log("Variant found, using custom URL.");
document.getElementById("customize-btn").href = fields[variant.id];
}
}
//Script that was added
document.getElementById('customize-btn').addEventListener('click', function(){
window.event.preventDefault();
var fields = JSON.parse('{{ product.metafields.decify | json }}');
var current_variant = document.getElementsByName('id')[0].value;
var decify_link = fields[current_variant];
console.log('current', current_variant);
document.location.href = decify_link;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment