Last active
May 8, 2019 08:54
-
-
Save andreibabor/532897f5b00a238ff6e5bb7adf161614 to your computer and use it in GitHub Desktop.
Shopify: Metafield Variant
This file contains hidden or 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
<!-- begin metafield --> | |
<div id="div1"></div> | |
<script type="text/javascript"> | |
var variants = {}; | |
{% for variant in product.variants %} | |
variants[{{variant.id}}] = "{{ variant.metafields.product_info.pdf}}"; | |
var div1=document.getElementById("div1"); | |
var newlink = document.createElement('a'); | |
newlink.setAttribute('class', 'link {{variant.id}}'); | |
// newlink.setAttribute('href', '{{ variant.metafields.product_info.pdf }}'); | |
newlink.setAttribute("target", "_blank"); | |
newlink.innerHTML="<span>Click here</span> to see our Certificate of Analysis report</a>" | |
{% unless variant.metafields.product_info.pdf contains '#' or variant.metafields.product_info.pdf == blank %} | |
div1.appendChild(newlink); | |
{% endunless %} | |
{% endfor %} | |
</script> | |
<!-- end metafield --> |
This file contains hidden or 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
#div1{ | |
.link{ | |
display: none; | |
font-weight: 700; | |
color: #343434; | |
span{ | |
color: #69f; | |
} | |
} | |
a[href^="#"]{ | |
display: none !important; | |
} | |
} |
This file contains hidden or 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
//de cautat variable callback din theme.js | |
if (variant.available) { | |
$('#div1 a:nth-child(1)').attr("href",(variants[variant.id])).css( "display", "block" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment