| @@ -52,8 +52,10 @@ | ||
| 52 | 52 | |
| 53 | 53 | add_action('woocommerce_variation_set_stock', array($this, 'purge_product_page'), 10, 1); |
| 54 | 54 | add_action('woocommerce_product_set_stock', array($this, 'purge_product_page'), 10, 1); |
| 55 | 55 | |
| 56 | + add_filter('wpo_page_cache_preloader_dont_close_browser_connection', array($this, 'preloader_dont_close_browser_connection'), 10, 1); | |
| 57 | + | |
| 56 | 58 | /** |
| 57 | 59 | * List of hooks for which when executed, the cache will be purged |
| 58 | 60 | * |
| 59 | 61 | * @param array $actions The actions |
| @@ -432,8 +434,26 @@ | ||
| 432 | 434 | if (!empty($this->config['enable_page_caching'])) { |
| 433 | 435 | wpo_cache_flush(); |
| 434 | 436 | WPO_Page_Cache::instance()->file_log("Full Cache Purge triggered by action: " . current_filter()); |
| 435 | 437 | } |
| 438 | + } | |
| 439 | + | |
| 440 | + /** | |
| 441 | + * Filter to set the flag to not close the browser connection when running via AJAX in the preloader. | |
| 442 | + * | |
| 443 | + * @param bool $dont_close_browser_connection The current value of the flag to not close the browser connection. Default is false. | |
| 444 | + * | |
| 445 | + * @return bool | |
| 446 | + */ | |
| 447 | + public function preloader_dont_close_browser_connection($dont_close_browser_connection) { | |
| 448 | + if ($dont_close_browser_connection) return $dont_close_browser_connection; | |
| 449 | + | |
| 450 | + // In WooCommerce, when the stock is updated for a product or a variation, it triggers an AJAX request in the background. | |
| 451 | + // In this case, we want to avoid closing the browser connection in the preloader, to allow the product edit page to receive the response. | |
| 452 | + if (did_action('woocommerce_variation_set_stock') || did_action('woocommerce_product_set_stock')) { | |
| 453 | + return true; | |
| 454 | + } | |
| 455 | + return false; | |
| 436 | 456 | } |
| 437 | 457 | |
| 438 | 458 | /** |
| 439 | 459 | * Triggered by wpo_cache_config_updated. |