Cache Not Cleared When WooCommerce Scheduled Sales Action Runs
Ran into an issue where a product was on sale but was not displaying the proper price on the product page. It showed the sale price in the cart and at checkout, but the product page was cached and was showing an old price. There's an action that gets run everyday at midnight, "woocommerce_scheduled_sales". There needs to be a function to purge the entire cache when that action runs.
@thekendog please look into: https://docs.litespeedtech.com/lscache/lscwp/cache/#woocommerce-tab might be usefull
@timotei-litespeed yeah, I know the settings that are there. But as you can see in those settings, it only clears the cache for the product when the stock or quantity changes. Not when a scheduled sale starts.
@thekendog Disabling LSC fixes the issue? I saw this PR: https://github.com/woocommerce/woocommerce/pull/62115
@timotei-litespeed hmmmm that bug might be related. I'm seeing the "drifting" of the AS action timing. Supposed to be at midnight, but it appears to have been bumped up to 11:57pm.
My question is, the action that runs doesn't appear to update the quantity or stock of a product. So even if the timing was correct, would LSC purge the cache? Does LSC get triggered during $product->save(); ?
https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/wc-product-functions.php#L524
@thekendog I made some tests and LSC do not trigger purge during $product->save();
@timotei-litespeed okay so I think even if the WooCommerce bug gets fixed, there still needs to be a purging of the cache when the scheduled sales starts. I would recommend purge all in case products are displayed on the front page, etc.
@thekendog I agree to clear cache. But let's think about about how to implement this: is clearing all alright to run on any changes? how could we know if products are added to homepage? not all sites has this feature :)
Maybe add a setting?
Option 1: Purge all. Runs on the "woocommerce_scheduled_sales" hook. Option 2: Purge individual products. Runs on the "wc_after_products_starting_sales" and "wc_after_products_ending_sales" hooks, both of which provide an array of product IDs. Probably make this the default.
Either way, there probably should be something. The default TTL for the cache is 7 days (too high IMO) and if I have a 3 day sale in the middle there then nobody will see the sale price.
@thekendog try adding: wc_after_products_starting_sales to setting https://docs.litespeedtech.com/lscache/lscwp/cache/#purge-all-hooks
Yeah, I've already done something similar on my end. Not everybody knows how to do this though, which is why I think it should be a setting somewhere in the WooCommerce tab with Option 2 set as the default.
I get your point but at this moment there are no plans to change this. Let me talk to the team and I will come back with a final answer. Thank you