• Resolved Luke Boobyer

    (@lsbwebdesign)


    Hi I need to change the how the cookie is set, so instead of being linked to the popup acceptance it is instead linked to a cookie acceptance button.

    I’ll be displaying a cookie policy popup along the bottom of my site, this has an Accept Cookies button. After clicking accept I need the age verification cookie to be added.

    Is there anyway of achieving this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @lsbwebdesign,

    It’s possible… but;

    I think it could be argued that the age gate cookies fall into the “necessary cookies” category. Here’s a bit from one of the GDPR sites:

    Strictly necessary cookies — These cookies are essential for you to browse the website and use its features, such as accessing secure areas of the site. Cookies that allow web shops to hold your items in your cart while you are shopping online are an example of strictly necessary cookies. These cookies will generally be first-party session cookies. While it is not required to obtain consent for these cookies, what they do and why they are necessary should be explained to the user.

    All well and good, but I appreciate it’s such a grey area that it’s better to be safe than sorry.

    I think there’s two solutions here. Firstly, rather than wait for the user to accept all the cookies, you could get express permission for the age gate one as part of the age gate form. This might be a bit of a better user experience than them having to accept cookies first, then enter their detail or click the yes/no.

    If you want to take this approach, there’s pretty much this exact thing (a few words aside) over on the documentation here.

    Otherwise – and to actually answer the question – you can use the age_gate_set_cookie filter. You can use the PHP version of this in both standard and JS modes, though a JS version of the hook is available.

    Here’s what you’d do;

    
    add_filter('age_gate_set_cookie', function($set_cookie){
    
      if (!cookies_allowed()) {
        $set_cookie = false;
      }
    
      return $set_cookie;
    
    }, 50);
    

    The cookies_allowed function there would hopefully come from whatever you popup is. I know this one has an is_cookie_allowed function, but you could probably write your own test pretty easily as the consent banner will most likely set a cookie you can check for!

    With this approach, I’d probably add a message using the age_gate_before or age_gate_after filter so users are aware they need to accept cookies first.

    Hope that’s helpful, shout if not.

    Thanks
    Phil

    Thread Starter Luke Boobyer

    (@lsbwebdesign)

    That’s brilliant thanks for the detailed reply Phil.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change how cookie is set’ is closed to new replies.