TranslationEditor
4 weeks ago
BundledItemHooks.php
4 weeks ago
Factory.php
4 weeks ago
MulticurrencyHooks.php
4 weeks ago
class-wcml-product-bundles.php
4 weeks ago
class-wcml-wc-product-bundles-items.php
4 weeks ago
BundledItemHooks.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\WcProductBundles; |
| 4 | |
| 5 | class BundledItemHooks implements \IWPML_Action { |
| 6 | |
| 7 | const EARLY_PRIORITY = 0; |
| 8 | const LATE_PRIORITY = 100; |
| 9 | |
| 10 | public function add_hooks() { |
| 11 | add_action( 'woocommerce_before_bundled_items', [ $this, 'beforeFrontendBundledItems' ] ); |
| 12 | } |
| 13 | |
| 14 | public function beforeFrontendBundledItems() { |
| 15 | add_action( 'woocommerce_bundled_item_details', [ $this, 'trackBundledItem' ], self::EARLY_PRIORITY ); |
| 16 | } |
| 17 | |
| 18 | public function trackBundledItem( $bundleItem ) { |
| 19 | $setProductId = function( $productId ) use ( $bundleItem ) { |
| 20 | return $bundleItem->get_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_bundled_item_details', $unsetProductId, self::LATE_PRIORITY ); |
| 29 | } |
| 30 | |
| 31 | } |
| 32 |