Alert does not stay closed on refresh

Hi team

I have created an alert but when closing it , it just re-appears when refreshing or visiting another page

I have given it an id ‘alert’

I added this code I found in another post:

jQuery(function( $ ){
$('#alert .close').click(function( e ){
  	/* expire in 1 day */
    Cookies.set('#alert', 'closed', { expires: 1 , path: ''});
});
if( Cookies.get('#alert') === 'closed' ){
    $('#alert').hide();
}  
});

That did not work and when checking the console I see this error

  Uncaught ReferenceError: Cookies is not defined
at HTMLDocument.<anonymous> ((index):1643)
at i (jquery.js?ver=1.12.4-wp:2)
at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4-wp:2)
at Function.ready (jquery.js?ver=1.12.4-wp:2)
at HTMLDocument.J (jquery.js?ver=1.12.4-wp:2)

Can you see what is wrong?

Thanks Q

Hi @quinex,

Thanks for reaching us.

If the alert still comes after you re-load the window, that means the Cookie is not set correctly.
Also check whether required Cookie library is properly loaded or not.
To know more about how cookies can be set you can go through this article.

You should also check the browser compatibility of the code you have written, the above mention article will help you on this.
You can also find a sample code that may help you to set the Cookie properly.

Hope it helps.

Thanks

@tristup
I’m not familiar with this… it is a cookie code from you guys.

And if the library loads well or not, that should be managed by Pro isn’t it

Hello @quinex ,

Please be advised that not all codes will work in general. It is usually a tailored solution to one specific site. Kindly provide us the URL of your site so that we can check it.

Best Regards.

Hello @quinex,

I can confirm the error in your code. I also found out the original thread where you got the code from. Regretfully we do not maintain any custom code. Keep in mind that codes were given specific to a particular. It does not work for you because you are missing some pieces of the code.

Note: We are unable to provide support for this customization request under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One or Care service for further assistance.

For the meantime, please check out this links:

As an alternative, you can use the Info bar feature by installing the ConvertPlus plugin. This plugin should be able to help you to have an info bar with more controls over it. And you do not have to code anymore. all the functionalities were already provided by the ConvertPlus plugin. To install it, simply go to Pro > Validation > Extensions. You can read more about the plugin here:

Thank you for your understanding.

Hi

This is quite disappointing… you provided the code to help someone else but now suddenly you won’t… or probably don’t know how to do it either and therefore just suggest something else?

So please tell me what is the difference that Themeco writes a solution code for another user and now decides not to?

Especially when you mention that you can confirm an error in the code, why not explain what that error is so I and other users can learn from it?

It should actually be a setting in the theme to be honest.

Convertplus is definitely not the same and the way it functions is also quite different.

Too bad that you guys choose the easy way out

Hey @quinex,

Thank you for your feedback and I understand it’s disappointing. Don’t worry I’ll add this to our feature request list so our development team will know what features the users need.

The custom codes we provide are only to provide guidance. They’re only to help users get started with custom coding. We do not create features on the fly. We’re sorry if this wasn’t made clear here in the forum. But, it’s stated in our Terms though. See https://theme.co/terms. That is already the case even back then however, some support staff just forget to make it clear.

Support

Support includes any questions pertaining to features of the themes or plugins to which You hold a valid and unexpired theme or plugin license. Customization requests are not covered. For example, if You have a question for how to use the bar feature in Pro, a member of Our team will be happy to explain how it works. If You want custom code to change a core feature of the bar feature, that would not be covered. For the avoidance of doubt, a customization request is any request that looks to change something in the theme that can not be altered using native options. The manner and scope of support provided is at Our sole discretion.

If you need guidance on custom development, you can now avail of our One service where we provide answers for customization questions. See https://theme.co/one

Thank you for understanding.

I do understand you changed the business model and most requests that were solved as support previously, now have to be purchased, but in another thread another user asked the same, received the code form you guys, it didn’t work, and he got a working solution… now how is this different… your colleague mentioned there was an error in the code, so then it would be quite customer friendly to mention what it is isn’t it?

Hi @quinex,

There must be some confusion, we don’t really provide customization here in the forum. What was provided is just an idea, but not to solve the customization issue. We don’t pick who will be given with the code, it depends on to which it is being applied. For example, let’s say a user has a simple issue and it’s not product related, but it happens that we, as support, are familiar with it based on one’s experience, then we can simply provide some guide and what was provided has no guarantee to work for anyone, and t’s always personal advice. On another example, there is user issue that we don’t understand and need further customization. Then that’s when we can’t provide some code or guidance since we’re not familiar with it and it’s not part of our product features.

Now let’s take the client as a sample where you said you’re able to get a code, that client already implemented his own Cookie library which works okay on his site. And that’s something we don’t implement or familiar with, but given it’s already set up, then what we just provided is a simple code to properly use that said library. Which again, will or may not work depending on setup, and it happens to work on his setup.

Now, your issue is not with the code, it’s the issue with cookie library that isn’t present from your site. In which clearly visible from the error you’re getting. And with that, we as a support aren’t familiar with its implementation and we can’t really answer that. We initially check the client’s site if it’s an easy one or if we’re familiar with it, then offer some guidance if it’s just a very simple one.

Again, as a summary, we may able to provide some guidance on an issue in which personally, we as support already understand even if it’s not part of our theme/plugin features. But it’s strict that we don’t provide support outside the product we offers.

Thanks for understanding.

Hi Rad,

is the cookie library not part of jQuery that is supposed to be loaded by the theme?

Just trying to understand.

Hi @quinex,

There was part of it in the jQuery but it’s no longer maintained, based on what I’m seeing, it was last updated in 2014. The jQuery is a library in which anyone can add another library as a jQuery plugin. But the jQuery version of WordPress isn’t the same as the other jQuery provided in https://jquery.com/. It’s a minified version and with minimal features.

On that client’s thread/post, there are two code given, the first one is jQuery specific in which no longer works since WordPress’ jQuery doesn’t have it. The second one is using Cookie(), which is a javascript object not related to jQuery, it must be implemented by a 3rd party plugin which we’re not sure which. It just happens it’s already available by checking and testing it on browser’s console.

Thanks!

Hi Rad,

I have solved it.

Used to functions get and set cookies as found on w3schools and then used the script as found earlier with slight mod

Added it all in the head of the pages through functions.php

I will share here how it is done so it might help other people until you guys might implement the feature in the alert element settings.


  1. Create the alert

  2. Give the alert an ID (also helps if you have more then 1 alert)

  3. add the following to the head of the page

//get cookie source w3schools
function getCookie(cname) {
var name = cname + “=”;
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(’;’);
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ’ ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return “”;
}

//set cookie source w3schools
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays2460601000));
var expires = “expires=”+ d.toUTCString();
document.cookie = cname + “=” + cvalue + “;” + expires + “;path=/”;
}

//the cookie function that keeps it closed fro a day
jQuery(function( $ ){
$(’#alert .close’).click(function( e ){
/* expire in 1 day */
setCookie(’#alert’, ‘closed’, 1);
});
if( getCookie(’#alert’) === ‘closed’ ){
$(’#alert’).hide();
}
});

the reason why I added it in the head is that it will keep it closed because the script is loaded before the actual header… otherwise you see the alert briefly loaded and then closed.

So most confusion was because of miscommunication…

Glad to hear that you’ve coded what you need. It is just important that we do not provide that ourselves to avoid being locked into a task that is really beyond a product support service. I’ll make all support staff know of this to avoid this kind of problem in the future. The root cause of this is failure to manage your expectation and once again, we apologize.

@christian

I understand your teams position and I want to apologize as well for the fact that I might have come over a bit too strong.

A solution was found which is most important and hopefully your team may include options like this to be selected by default in upcoming releases.

Just like having animation options (good ones) that would be a major addition to the theme.

Until then, have a great day/evening

Cheers Q

Hey @quinex,

Thank you very much for you feedback. Yes, the animation options is been under development. It will be added in the future release of the theme.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.