Created
June 2, 2017 19:49
-
-
Save VizualAbstract/e93e098e49935e619052d64a584f677d 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
function getProductForm(product_id) { | |
var forms = document.querySelectorAll('[action^="/cart/add"]'); | |
if (!forms.length) { | |
alert('ReCharge cannot load: Product form not found.'); | |
return false; | |
} else if (forms.length > 1) { | |
var product_form; | |
forms.forEach(function(form, i) { | |
if (form[i] && form[i].getAttribute('data-productid') !== null) { | |
if (form[i].getAttribute('data-productid') == product_id) { | |
productForm = form[i]; | |
} | |
} else if (form[i] && form[i].getAttribute('data-product-id') !== null) { | |
if (form[i].getAttribute('data-product-id') == product_id) { | |
productForm = form[i]; | |
} | |
} else { | |
alert('ReCharge cannot load: Product form not found for: ' + product_id); | |
productForm = false; | |
} | |
}); | |
return productForm; | |
} else { | |
return forms[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment