wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
688 stars 216 forks source link

HTTP 403 error ajax calender with WooCommerce bookings plugin stops working randomly. #3275

Closed elbauldelgeek closed 2 months ago

elbauldelgeek commented 3 years ago

Describe the bug At random, the user who accesses the website receives a 403 error in the loading of the calendar , if I disable the wp-rocket, the problem is fixed.

GET /?wc-ajax=wc_bookings_find_booked_day_blocks&product_id=835&wc-ajax=wc_bookings_find_booked_day_blocks&security=1b8080b274&min_date=2020-10-05&max_date=2020-11-12 HTTP/1.1" 403 33 "https://www.test.com/producto/product1-diver/" GET /?wc-ajax=wc_bookings_find_booked_day_blocks&product_id=835&wc-ajax=wc_bookings_find_booked_day_blocks&security=1b8080b274&min_date=2020-10-05&max_date=2020-11-12 HTTP/1.1" 403 33 "https://www.test.com/producto/product1-diver/"

To Reproduce Steps to reproduce the behavior:

  1. Create a woocomerce product with woocomerce bookings inside.
  2. Enable WP-Rocket
  3. Access from one browser to this product every 10min aprox
  4. See error , the booking calendar remains loading

Woocomerce bookings version: 1.15.29 Woocomerce version: 4.6.2 WP-rocket version 3.7.5 Wordpress version: 5.5.3

Expected behavior Calender for Bookings work

Screenshots I put in the here

https://ibb.co/fNvBxWh

Additional context

I tried to fix the problem with this exceptions, the problem continue

-Exclusion CSS

/wp-content/plugins/woocommerce-bookings/(.).css /wp-content/plugins/woocommerce-bookings/dist/css/(.).css

-Exclusion JS /wp-content/plugins/woocommerce-bookings/dist/js/lib/(.).js /wp-content/plugins/woocommerce-bookings/ /wp-content/plugins/woocommerce-bookings/dist/(.).js /wp-content/plugins/trustpilot/review/assets/js/(.*).js /wp-content/plugins/woocommerce-bookings/dist/frontend.js

scheibling commented 3 years ago

@elbauldelgeek did you ever find a solution to this? Stumbling upon the same issue now

elbauldelgeek commented 3 years ago

Hello @scheibling ,

No, I did . Finally I needed to disable all cache and Minify. I contacted with WP-Rocket or open this issue. and they don't provide me any kind of solution.

scheibling commented 3 years ago

Thanks for your answer, kind of in the same boat at the moment... Although I've now found a solution which seems to work, we'll see when our cache expires tonight. There's a cookie which needs to be excluded from caching, wp_woocommerce_session, seems to have worked for me

thinkjarvisdesignandmarketing commented 1 year ago

@scheibling @elbauldelgeek

Can you confirm if you found a solution to this. My solution and explanation is below based on your answers.

I too am getting this issue June 2023. The calendar just randomly stops loading in the front end.

I use WP-Rocket - Latest version - just using caching. No minification or merging - This is handled by our theme and does not affect plugins.

It appears that if you set a cache life beyond 2 days then the session data is getting cached for too long. Generally speaking I set a cache lifespan of 28 days to reduce server load. This appears to be incompatible with WordPress Bookings.

image

If scheibling is right with the cookie cache - The wp_woocommercesession cookie has a max lifespan of 2 days by default. So as long as the cache life is less than 2 days the booking cache should refresh. So setting the cache to 10 hours (The default length) this should solve the problem.

However if not - Exclude the cookie from cache - That will definitely solve the issue.

That is the theory - I have a live client site where I am implenting this fix.

Of course if you have defer and delay JS turned on - this may be a seperate issue.

thinkjarvisdesignandmarketing commented 1 year ago

Note I have gone for 8 hour cache life so the cache clears 3 times every 24 hours.

This should prevent the issue but will put slightly increased load on the server during cache rebuilds. We have an 8 core VPS with 24gb of ram. It is a beasty. So this wont be a problem.

The issue is fully described here with a solution - See point 3. https://woocommerce.com/document/bookings-faq/#section-11

Although it refers to WPEngine - WP Engine uses Cloud Flare CDN for page caching and also appears to cache cookies the same way WP Rocket does according to the issue we are seeing. The recommended solution is excluding woocommerce cookies from cache.

A full list of cookies to exclude is here. I am trying the solution above with just wp sessions excluded. But may have to exclude the two cart cookies as well if the problem persists. https://woocommerce.com/document/woocommerce-cookies/#section-2

thinkjarvisdesignandmarketing commented 1 year ago

Solution I have contacted WP-Rocket and they have confirmed the issue - WooCommerce Bookings adds a unique session token into the HTML file. This means WP-Rocket page caching is not compatible with WP-Bookings.

To make it compatible WP-Rocket have recommended excluding all bookable products from cache or using their helper plugin which allows you to disable caching but still enable everything else like lazy load and script merging etc.

OR

As per WooCommerce Bookings FAQs add all WooCommerce Cookies to the excluded list in WP-Rocket.

I hope this helps others.

I have raised a support ticket with WooCommerce asking them to update the documentation.

WooCommerce bookings remains one of the most poorly supported add-ons for WooCommerce. Its actually criminal.

thinkjarvisdesignandmarketing commented 1 year ago

I reported the issue to WooCommerce - They have updated the wording of the documentation for the Plugin - Clearly stating the correct way to prevent the problem.

You can also just exclude the booking product/page itself rather than the Cookie from cache in WP-Rocket. This has the same effect.

Point 3 has been updated as a result of me raising the issue. https://woocommerce.com/document/bookings-faq/#section-11

piotrbak commented 2 months ago

There's nothing we could do on our side in the code to resolve this issue. Feel free to reopen the issue.

thinkjarvisdesignandmarketing commented 2 months ago

@piotrbak Thank you - I understand - The issue is with the way the cookies work with the bookings plugin. Nothing Wp-Rocket can do.

The correct action to take for anyone else finding this post is to exclude the bookable product pages from the cache. Or Add the WooCommerce Bookings Cookies to the cookie exclusions in WP-Rocket.

Is it possible to get a section added to the WP-Rocket Documentation on this? It would help others if they are having problems and search for the problem.

piotrbak commented 2 months ago

That's reasonable, indeed.

@camilamadronero What do you think about this one?

thinkjarvisdesignandmarketing commented 2 months ago

From the documentation - Updated after I raised the concern with WooCommerce.

Why is the calendar not displaying on bookable products? Typically, issues like this are a result of plugins that offer caching features or server-side caching from services like WP Engine or Cloudflare. It’s a good idea to clear all cache using the available options from those services and temporarily disable all active plugins related to caching and/or performance.

Listed below are alternative suggestions to troubleshoot a calendar that may not be displayed on a bookable product’s page.

If you are using Cloudflare, you may need to disable Rocket Loader as it might be interfering with the calendar’s JavaScript.

If you’re using Chrome or Firefox, review the console for errors or conflicts on the product that should be displaying the product’s calendar.

If your website is hosted on WP Engine, or if you’re using caching plugins, or if your hosting provider has set up server-side caching, you might come across a situation where the booking product page’s calendar keeps loading indefinitely. Alongside, you might notice a 403 error in the browser console. This issue emerges due to the utilization of a session token named wp_woocommercesession native to WooCommerce to monitor user interactions. The caching mechanisms in place on the site can disrupt the dynamic loading of booking pages, including the calendar since both rely on accurate availability data. Often, the expiration settings of caching plugins and mechanisms exceed the default expiry of the wp_woocommercesession token (2 days).

To resolve this, the recommended step is to get contact your hosting provider or the developer of the caching plugin. You can request them to exclude all WooCommerce cookies from being cached. You can find a comprehensive list of WooCommerce cookies in this document for reference. If the caching developer is not responsive, please disable the caching plugin and check the booking calendar.

camilamadronero commented 2 months ago

Hey there!

As per this, it seems like the problem happens only if customers are using a 2 days or higher Cache Lifespan, which is not commonly done.

So, unless I'm missing something, this 403/nonce issue is already generally documented here: Nonces and Cache lifespan.

If you insist, we could add a mention here: Using WP Rocket on your WooCommerce site. To do this, can you tell me if this one is the right affected plugin?

thinkjarvisdesignandmarketing commented 2 months ago

It is not that I insist @camilamadronero. It is that more non-technical users wont find the information in the official plugin documentation because it doesnt specifically reference WP-Rocket.

This needs adding to WP-Rockets documentation - As an advanced/expert user - I couldnt find this information which is why I got Woo to update the documentation with the notes above and why I am asking for it to be added specifically to WP-Rocket so other wp-rocket users can actually find this informtation.

Unfortunately changing the cache lifespan to a few hours doesnt work in practice because there will eventually be an overlap with the cookie expiry meaning some visitors still wont be able to use the booking system. The only solution is to disable caching on bookable products. - Either by exluding the WooCommerce Bookings Cookie or just setting each bookable product to do not cache in wp-rocket settings.

It is not covered at all by the Nonces and Cache Lifespan link you shared - To start with this post does not even use the words WooCommerce Bookings for example. So 100% not google indexible for anyone trying to find information about this. The objective here it to create some content in the documentation that clearly mentions the plugin and the solution so other WP-Rocket users can get this information if they google for it.

The other option is WP-Rocket adds a new feature that auto-excludes bookable products when WooCommerce Bookings is enabled. But I wont Insist on this.

This needs its own addition somewhere in the documentation - Specifically referencing the WooCommerce Official Bookings plugin. With a WP-Rocket specific version of the text that WooCommerce added to the documentation in which I copy and pasted in my last post on this thread.

The solution is to either exclude the booking cookie or just exclude the url of any bookable product from WP-Rockets cache.

Can we get this added to the documentation?

Yes you have the right plugin.

camilamadronero commented 1 month ago

Alright, thanks! From WP Rocket's perspective, it made more sense to document this, along with other two known conflicts in the main nonces article, here: https://docs.wp-rocket.me/article/975-nonces-and-cache-lifespan