Our website is currently running on an outdated e-commerce CMS platform, which limits my options due to my beginner level skills in JavaScript and jQuery.
One specific issue we are facing is the need to hide Prices and Add to Cart buttons for users who are not logged in. I have a script that has worked in the past by checking user's cookies, however, it seems to be malfunctioning after modifying it for our new site.
I suspect I may have made a simple mistake in the syntax, so if someone could review my script quickly and point out where I went wrong, I would greatly appreciate it!
<script type="text/javascript">
function DisplayAuthorizedContent(name) {
var cookies=document.cookie;
var start = cookies.indexOf(name + "=");
var name = "";
var start1;
var end1;
var tmp;
var signed_in = -1;
if (start != -1) {
start = cookies.indexOf("=", start) +1;
var end = cookies.indexOf("|", start);
if (end != -1) {
signed_in = cookies.indexOf("|yes", start);
name = unescape(cookies.substring(start,end-1));
if (signed_in != -1) {
$('.loginFilter').show();
}
}
}
if (signed_in == -1) {
$('.loginFilter').empty();
$('.addMessage').each(function(){
$(this).append('Requires Wholesale Account to Purchase.<br><br><a href=\"#\" class=\"applyLink\">Apply Here<\/a>');
$(this).show();
});
}
}
DisplayAuthorizedContent("ss_reg_000778370");
</script>
The HTML
<div class="loginFilter addMessage"><a href="#">Add to Cart Example</a></div>