lscache_wp icon indicating copy to clipboard operation
lscache_wp copied to clipboard

Cache Not Cleared When WooCommerce Scheduled Sales Action Runs

Open thekendog opened this issue 1 month ago • 11 comments

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 avatar Dec 02 '25 18:12 thekendog

@thekendog please look into: https://docs.litespeedtech.com/lscache/lscwp/cache/#woocommerce-tab might be usefull

timotei-litespeed avatar Dec 02 '25 19:12 timotei-litespeed

@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 avatar Dec 02 '25 19:12 thekendog

@thekendog Disabling LSC fixes the issue? I saw this PR: https://github.com/woocommerce/woocommerce/pull/62115

timotei-litespeed avatar Dec 02 '25 20:12 timotei-litespeed

@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 avatar Dec 02 '25 21:12 thekendog

@thekendog I made some tests and LSC do not trigger purge during $product->save();

timotei-litespeed avatar Dec 03 '25 15:12 timotei-litespeed

@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 avatar Dec 03 '25 18:12 thekendog

@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 :)

timotei-litespeed avatar Dec 03 '25 20:12 timotei-litespeed

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 avatar Dec 03 '25 20:12 thekendog

@thekendog try adding: wc_after_products_starting_sales to setting https://docs.litespeedtech.com/lscache/lscwp/cache/#purge-all-hooks

timotei-litespeed avatar Dec 03 '25 21:12 timotei-litespeed

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.

thekendog avatar Dec 03 '25 21:12 thekendog

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

timotei-litespeed avatar Dec 03 '25 21:12 timotei-litespeed