ProductHooks.php
25 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\DisplayAsTranslated; |
| 4 | |
| 5 | use WPML\LIB\WP\Hooks; |
| 6 | use function WCML\functions\flushProductCachePrefixById; |
| 7 | |
| 8 | class ProductHooks implements \IWPML_Frontend_Action { |
| 9 | |
| 10 | public function add_hooks() { |
| 11 | Hooks::onAction( 'wp' )->then( [ $this, 'flush_current_product_cache_prefix' ] ); |
| 12 | } |
| 13 | |
| 14 | public function flush_current_product_cache_prefix() { |
| 15 | if ( ! is_singular( 'product' ) ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | $product_id = get_queried_object_id(); |
| 20 | if ( $product_id > 0 ) { |
| 21 | flushProductCachePrefixById( $product_id ); |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 |