CompositedProductHooks.php
3 weeks ago
Factory.php
3 weeks ago
JobHooks.php
3 weeks ago
MulticurrencyHooks.php
3 weeks ago
class-wcml-composite-products.php
3 weeks ago
CompositedProductHooks.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\WcCompositeProducts; |
| 4 | |
| 5 | class CompositedProductHooks implements \IWPML_Action { |
| 6 | |
| 7 | const EARLY_PRIORITY = 0; |
| 8 | const LATE_PRIORITY = 100; |
| 9 | |
| 10 | public function add_hooks() { |
| 11 | add_action( 'woocommerce_composited_product_variable', [ $this, 'beforeFrontendCompositedProduct' ], self::EARLY_PRIORITY ); |
| 12 | } |
| 13 | |
| 14 | public function beforeFrontendCompositedProduct() { |
| 15 | add_action( 'woocommerce_composited_product_details', [ $this, 'trackCompositedProduct' ], self::EARLY_PRIORITY ); |
| 16 | } |
| 17 | |
| 18 | public function trackCompositedProduct( $product ) { |
| 19 | $setProductId = function( $productId ) use ( $product ) { |
| 20 | return $product->get_id(); |
| 21 | }; |
| 22 | |
| 23 | $unsetProductId = function() use ( $setProductId ) { |
| 24 | remove_filter( 'wcml_translated_attribute_label_product_id', $setProductId ); |
| 25 | }; |
| 26 | |
| 27 | add_filter( 'wcml_translated_attribute_label_product_id', $setProductId ); |
| 28 | add_action( 'woocommerce_composited_product_variable', $unsetProductId, self::LATE_PRIORITY ); |
| 29 | } |
| 30 | |
| 31 | } |
| 32 |