Support » Plugin: YITH WooCommerce Wishlist » WP-Super-Cache wpsc_add_cookie support
WP-Super-Cache wpsc_add_cookie support
-
Is it possible to add in support for WP-Super-Cache WPSC)?
This can be done, I guess, by utilizing the
wpsc_add_cookie
function in WPSC. @donncha has this explained in his blog post https://odd.blog/2018/07/20/wp-super-cache-and-cookie-banners/. From what I understand, WPSC then builds a different cache file per cookie (https://wordpress.org/plugins/wp-super-cache/).
A current downside of YITH WooCommerce Wishlist is the session-id that’s added to the cookie name. This makes it hard to add it in ado_action
.For now I’ve altered my .htaccess rewrite rules to exclude
yith_wcwl_(session|products)
cookies from caching, but as you may understand that is not optimal.Or do you have a better solution?
-
Hi Jan
I would be happy to add required code to plugin in order to automatically exclude cache for users with a wishlist set
Anyway, I tried to execute the suggested code
function yith_wcwl_exclude_from_wp_super_cache(){ do_action( 'wpsc_add_cookie', YITH_WCWL_Session()->get_session_cookie_name() ); } add_action( 'init', 'yith_wcwl_exclude_from_wp_super_cache' );
and it didn’t produce the expected result
Do you think you could test it and let me know if it properly works for you?
You just need to add the snippet at the end of functions.php file of your theme or child in order to execute itI’ll proceed with further testing, but unfortunately I’m afraid we need to delay this after 3.0.6, expected for today
Thanks for your positive reply, @yithemes.
Because it involves a site of one of our customer, this is a possible solution I need to test during a couple of days. I’ll get back as soon as possible, I think some time this Friday.
Unfortunately it didn’t produce the expected (wanted…) result for me as well. The number of items in the wishlist isn’t instantly updated on all pages (Ajax is on). I hoped the WP-Super-Cache wpsc_add_cookie functionality would create a seperate cachefile based on the cookie. However, wen using wpsc_add_cookie it adds the cookie to the cache *exclude* list in the .htaccess rewrite condition.
Maybe it’s best to put this support ticket on hold, as I currently don’t have a lot of time available to test and debug this. Or perhaps you can contact Donncha Ó Caoimh about how to add WPSC support in Yith WooCommerce Wishlist.
Anyway, to be continued 🙂
Hi again Jan
I’d love to hear @donncha opinion on this manner; maybe something is wrong with our approch, and we can correct it easly
Anyway, even without any specific integration, I was able to make wishlist correctly work on WP Super Cache
I simply added wishlist page to exclusions, as shown here, and enabled ajax loading of wishlist fragments (as you can see here)@janr – don’t use expert (mod_rewrite) caching, use simple. It’s just as fast and when you’re doing things like this it’s easier to debug.
Did you enable debugging in WP Super Cache? Did it say anything about finding the cookie and creating a new cache file?
Did you check your wp-cache-config.php to make sure the cookie was added to the cookie list?Hi Donncha, thank you for joining in and your reply. Much appreciated.
Following your advice, and using Simple mode seems to work better. I’ll have to do some extra testing and debugging in de next few days, but a separate cache file is created according to the debug functionality:
$ grep wishlist wp-content/wp-cache-config.php $cache_rejected_uri = array ( 0 => 'wp-.*\\.php', 1 => 'index\\.php', 2 => 'wishlist', 3 => 'wishlist/*', ); $ grep wpsc_cookies wp-content/wp-cache-config.php $wpsc_cookies = array ( 0 => 'yith_wcwl_session_15359811dc750423199e6f7bdde9ae51', );
13:07:47 247 /?add_to_wishlist=59016 wpsc_get_auth_cookies: no auth cookies detected 13:07:47 247 /?add_to_wishlist=59016 wpsc_is_caching_user_disabled: false 13:07:47 246 /product-tag/walk-around/page/148/?add_to_wishlist=10403 supercache dir: ABSPATH/wp-content/cache/supercache/www.example.com/product-tag/walk-around/page/148/ 13:07:47 247 /?add_to_wishlist=59016 wp_cache_get_cookies_values - found extra cookie: yith_wcwl_session_15359811dc750423199e6f7bdde9ae51 13:07:47 247 /?add_to_wishlist=59016 wp_cache_get_cookies_values: return: f3ac53821a909e42a6e4cce2a7ae2c9e 13:07:47 246 /product-tag/walk-around/page/148/?add_to_wishlist=10403 No Super Cache file found for current URL: ABSPATH/wp-content/cache/supercache/www.example.com/product-tag/walk-around/page/148/index-https.html 13:07:47 247 /?add_to_wishlist=59016 supercache dir: ABSPATH/wp-content/cache/supercache/www.example.com/ 13:07:47 247 /?add_to_wishlist=59016 No Super Cache file found for current URL: ABSPATH/wp-content/cache/supercache/www.example.com/index-https.html 13:07:47 247 /?add_to_wishlist=59016 wp_cache_get_cookies_values: cached: f3ac53821a909e42a6e4cce2a7ae2c9e 13:07:47 247 /?add_to_wishlist=59016 In WP Cache Phase 2 13:07:47 247 /?add_to_wishlist=59016 Setting up WordPress actions 13:07:47 247 /?add_to_wishlist=59016 Supercache caching disabled. Only using wp-cache. Non empty GET request. {"add_to_wishlist":"59016"} 13:07:47 247 /?add_to_wishlist=59016 Created output buffer 13:07:47 246 /product-tag/walk-around/page/148/?add_to_wishlist=10403 wp_cache_get_cookies_values: return: 13:07:47 246 /product-tag/walk-around/page/148/?add_to_wishlist=10403 wp_cache_phase2: No caching to do as user agent rejected. 13:07:50 247 /?add_to_wishlist=59016 URI rejected. Not Caching 13:07:50 247 /?add_to_wishlist=59016 wp_cache_maybe_dynamic: returned $buffer
And
13:25:57 223 /?add_to_wishlist=58998 wpsc_get_auth_cookies: no auth cookies detected 13:25:57 223 /?add_to_wishlist=58998 wpsc_is_caching_user_disabled: false 13:25:57 223 /?add_to_wishlist=58998 wp_cache_get_cookies_values - found extra cookie: yith_wcwl_session_15359811dc750423199e6f7bdde9ae51 13:25:57 223 /?add_to_wishlist=58998 wp_cache_get_cookies_values: return: f3ac53821a909e42a6e4cce2a7ae2c9e 13:25:57 223 /?add_to_wishlist=58998 supercache dir: ABSPATH/wp-content/cache/supercache/www.example.com/ 13:25:57 223 /?add_to_wishlist=58998 No Super Cache file found for current URL: ABSPATH/wp-content/cache/supercache/www.example.com/index-https.html 13:25:57 223 /?add_to_wishlist=58998 wp_cache_get_cookies_values: cached: f3ac53821a909e42a6e4cce2a7ae2c9e 13:25:57 223 /?add_to_wishlist=58998 In WP Cache Phase 2 13:25:57 223 /?add_to_wishlist=58998 Setting up WordPress actions 13:25:57 223 /?add_to_wishlist=58998 Supercache caching disabled. Only using wp-cache. Non empty GET request. {"add_to_wishlist":"58998"} 13:25:57 223 /?add_to_wishlist=58998 Created output buffer 13:25:59 223 /?add_to_wishlist=58998 URI rejected. Not Caching 13:25:59 223 /?add_to_wishlist=58998 wp_cache_maybe_dynamic: returned $buffer
@yithemes
The only issue now is that the ‘quick-wishlist’ is cached on previous pages and thus not increased / updated (I also tried https://support.yithemes.com/hc/en-us/articles/115001372967-Wishlist-How-to-count-number-of-products-wishlist-in-ajax).Hi again Jan
We offer a widget for the Wishlist (including count of items) in another version of the plugin
This will be loaded via ajax on page load, and will be refreshed with every action on the wishlist
I think this could work for your specific case, without requiring further hassle; you can check our site if you need more informationsOn the other hand, if you want to proceed with custom solution, and the code here works for you, I can suggest to tweak the js code, in order to recount items on page load:
jQuery( document ).ready( function( $ ){ var recountItems = function(){ var counter = $('.your-counter-selector'); $.ajax({ url: yith_wcwl_l10n.ajax_url, data: { action: 'yith_wcwl_update_wishlist_count' }, dataType: 'json', success: function( data ){ counter.html( data.count ); }, beforeSend: function(){ counter.block(); }, complete: function(){ counter.unblock(); } }) }; $(document).on( 'added_to_wishlist removed_from_wishlist', recountItems ); recountItems(); });
- The topic ‘WP-Super-Cache wpsc_add_cookie support’ is closed to new replies.