Hi,
I’m attempting to show an element in the product description based on a customer tag, but I’m not having any luck.
In my product template file:
{% stylesheet %}
#pdf-factsheet {
display: none;
}
{% if customer.tags contains "wholesale" %}
#pdf-factsheet {
display: block;
max-width: 120px;
}
.pdf-elements {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
{% endif %}
{% endstylesheet %}
Unfortunately the element always displays. Any ideas how I could do this?
Hi. @ChristyMc :
You can try adding that Styles to your product page instead of your main CSS file.
Thanks for your quick reply, I’m already doing that. I suppose liquid can’t check at runtime as the CSS is pre-compiled. May have to add with JS.
Ended up using jQuery to do this.
{% if customer.tags contains "wholesale" %}
<script>
$('#pdf-factsheet').removeClass('pdf-factsheet-hide');
$('#pdf-factsheet').addClass('pdf-factsheet-show');
</script>
{% endif %}
.pdf-factsheet-hide {
display: none;
}
.pdf-factsheet-show {
display: block !important;
max-width: 120px;
}
This is great. Thanks!
If I wanted this for every page, which file would be best? I’m using this to create a conditional banner in the header. I placed the jquery in the header file but the conditional CSS isn’t applying based on being logged in with different tags.
Does the CSS also need to be inline in the header? I have it in an existing style sheet right now.
Or is there a better template file to place the jquery in?