Having an issue performing event on Age Gate Success
-
Hey Phil,
Thanks for your initial help with capturing and using specific data from this thread. Leveraging some of that work, I have been trying to accomplish the following but am having an issue and not sure I am going about this the correct way…
Assuming a user passes the age gate, I am trying to display a modal if specific conditions are met but only have it display once (when the user passes the gate).
If sticking with the normal Age Gate (PHP) in order to leverage the custom
ag_data
cookie created, I am having a hard time figuring out how to accomplish this action once upon a user successfully entering the site.If switching to the JS version, it seems like I am unable to leverage the region data that is stored in the custom
ag_data
cookie.To give you some context, below should hopefully give you a better idea as to how I am thinking about this (this was when I started trying to do it with the JS version but then realized I was unable to leverage the region data that was being stored):
<?php // Shipping modal $shipping_state = strtoupper(ag_user_data()->region); $shipping_states = get_field('shipping_states', 'option'); if ( !in_array( $shipping_state, $shipping_states ) ) { get_template_part('modals/modal', 'not-shipping'); } ?> <script> jQuery(document).ready(function($) { $(window).on('agegatepassed', function() { if ( $.inArray(shipping_state, shipping_states) != -1 ) { Cookies.set("shipping-modal", "hide"); } else { Cookies.set("shipping-modal", "show"); $('#modal-not-shipping').modal('show'); } }); $('#modal-not-shipping').on('hidden.bs.modal', function (e) { Cookies.set("shipping-modal", "hide"); }) });
Any thoughts?
- The topic ‘Having an issue performing event on Age Gate Success’ is closed to new replies.