|
1 | | -<?php |
| 1 | +<?php |
2 | 2 | /** |
3 | 3 | * The Third Party integration with the WooCommerce plugin. |
4 | 4 | * |
@@ -85,6 +85,15 @@ public function add_hooks() { |
85 | 85 | add_action( 'woocommerce_variation_set_stock_status', [ $this, 'purge_product_stock_status' ], 10, 3 ); |
86 | 86 | add_action( 'woocommerce_order_status_cancelled', [ $this, 'purge_cancelled_order_products' ], 20 ); |
87 | 87 |
|
| 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 | + |
88 | 97 | add_action('comment_post', [ $this, 'add_review' ], 10, 3); |
89 | 98 |
|
90 | 99 | if ( $this->esi_enabled ) { |
@@ -693,6 +702,34 @@ public function purge_cancelled_order_products( $order_id ) { |
693 | 702 | } |
694 | 703 | } |
695 | 704 |
|
| 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 | + |
696 | 733 | /** |
697 | 734 | * Purge a product page and related pages (based on settings) on checkout. |
698 | 735 | * |
|
0 commit comments