Skip to content

Commit 309bbb2

Browse files
author
Hai Zheng
committed
v7.9-a26: Purge cache when WooCommerce scheduled sales action runs. (thekendog #941)
1 parent c786496 commit 309bbb2

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

thirdparty/woocommerce.cls.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
/**
33
* The Third Party integration with the WooCommerce plugin.
44
*
@@ -85,6 +85,15 @@ public function add_hooks() {
8585
add_action( 'woocommerce_variation_set_stock_status', [ $this, 'purge_product_stock_status' ], 10, 3 );
8686
add_action( 'woocommerce_order_status_cancelled', [ $this, 'purge_cancelled_order_products' ], 20 );
8787

88+
// Purge product pages when WooCommerce scheduled sales flip prices (#941).
89+
// Daily cron after-hooks (WC < 10.5 path, and post-10.5 safety net for products missed by AS):
90+
add_action( 'wc_after_products_starting_sales', [ $this, 'purge_products_on_sale_change' ] );
91+
add_action( 'wc_after_products_ending_sales', [ $this, 'purge_products_on_sale_change' ] );
92+
// Per-product Action Scheduler events (WC 10.5+, main path — fire at exact sale times).
93+
// Priority 99 runs after WC's default-10 callback so the price flip is committed before we purge.
94+
add_action( 'wc_product_start_scheduled_sale', [ $this, 'purge_products_on_sale_change' ], 99 );
95+
add_action( 'wc_product_end_scheduled_sale', [ $this, 'purge_products_on_sale_change' ], 99 );
96+
8897
add_action('comment_post', [ $this, 'add_review' ], 10, 3);
8998

9099
if ( $this->esi_enabled ) {
@@ -693,6 +702,34 @@ public function purge_cancelled_order_products( $order_id ) {
693702
}
694703
}
695704

705+
/**
706+
* Purge products whose sale status flipped (#941).
707+
*
708+
* Handles both WC paths:
709+
* - Daily cron after-hooks (`wc_after_products_starting_sales` / `wc_after_products_ending_sales`) → array of IDs.
710+
* - Per-product Action Scheduler events (`wc_product_start_scheduled_sale` / `wc_product_end_scheduled_sale`, WC 10.5+) → single ID.
711+
*
712+
* Force purge via `$stock_status_changed = true` so a price flip is not gated by the stock-update interval config.
713+
*
714+
* @since 7.9
715+
* @param int|int[] $product_ids Single product ID (per-product AS callback) or array of IDs (daily cron after-hook).
716+
* @return void
717+
*/
718+
public function purge_products_on_sale_change( $product_ids ) {
719+
if ( ! function_exists( 'wc_get_product' ) ) {
720+
return;
721+
}
722+
723+
foreach ( (array) $product_ids as $product_id ) {
724+
$product = wc_get_product( $product_id );
725+
if ( ! $product ) {
726+
continue;
727+
}
728+
do_action( 'litespeed_debug', '[3rd] Woo Purge sale change [pid] ' . $product->get_id() );
729+
$this->purge_product( $product, true );
730+
}
731+
}
732+
696733
/**
697734
* Purge a product page and related pages (based on settings) on checkout.
698735
*

0 commit comments

Comments
 (0)