This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have a view where I (by using a shortcode) insert a cookie value as a class attribute. This works fine when initially loading the page, but when clicking submit at the custom filters and the AJAX refresh option is selected, the cookie value returns blank. The strange part is, that the text ‘cookie’ and the $attr[0] value is returned, but just not the cookie value.
This is the shortcode script in functions.php
add_shortcode('get_cookie_value', 'get_cookie_value_func');
function get_cookie_value_func($attr) {
return 'cookie '.$attr[0].' = '.$_COOKIE[$attr[0]];
}
And this is the relevant part of my view:
<div class="grid products [get_cookie_value 'grid-products-[wpv-post-id]']">
Any Ideas?
I really don’t want to use the full page refresh option as it jumps to the top of the page and the view is not.
Thanks in advance 🙂
The cookie is saved from this jQuery function (when opening a parent container and not in conjunction with the AJAX refresh:
set_cookie_value (name, value, minutes=60) {
var date = new Date();
date.setTime(date.getTime() + (minutes * 60*1000));
jQuery.cookie(name, value, {expires: date});
}
In this case you're going to need to callback the function after our AJAX refresh has ran. So you will need to add your function again with the AJAX callback function for the search.
jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
/**
* data.view_unique_id (string) The View unique ID hash
* data.layout (object) The jQuery object for the View layout wrapper
*/
set_cookie_value (name, value, minutes=60) {
var date = new Date();
date.setTime(date.getTime() + (minutes * 60*1000));
jQuery.cookie(name, value, {expires: date});
}
});