The Problem:
Client website is on a custom WordPress + WooCommerce theme. https://jesslittle.com
When the WooCommerce store-wide banner is activated, it adds a class drop-low
to the main header, which drops it below the sitewide banner, so they reside on top of one another (this works).
What isn't working, is when the user dismisses the notification, it works on that page, but as soon as they navigate to a new page, the class comes back, and you're left with the blank space where the banner was.
What I've Tried:
It seems that the page refresh is the culprit so that should mean I need to add the document ready function, which I have? I've also read you need to add a cookie, but I'd like to avoid that. Also don't understand why I'd need to do that if the add class sticks on refresh?
The Code:
jQuery(document).ready(function () {
'use strict';
var c, currentScrollTop = 0,
navbar = jQuery('header');
jQuery(window).scroll(function () {
var a = jQuery(window).scrollTop();
var b = navbar.height();
currentScrollTop = a;
if (c < currentScrollTop && a > b + b) {
navbar.addClass("header--up");
} else if (c > currentScrollTop && !(a <= b)) {
navbar.removeClass("header--up");
}
c = currentScrollTop;
});
// IF STORE WIDE NOTICE IS ON ADD CLASS
if ($('p.woocommerce-store-notice')[0]) {
$('header.navigation').addClass('drop-low');
}
// IF DISMISS LINK IS CLICKED, DROP CLASS
$('.woocommerce-store-notice__dismiss-link').on('click', function(){
$('header.navigation').removeClass('drop-low');
})
});