Last active
August 19, 2020 18:43
-
-
Save blixxurd/020a68e2d11809fdd180d9597f7d7649 to your computer and use it in GitHub Desktop.
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
// 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