TranslationEditor
1 month ago
BundledItemHooks.php
1 month ago
Factory.php
1 month ago
MulticurrencyHooks.php
1 month ago
class-wcml-product-bundles.php
1 month ago
class-wcml-wc-product-bundles-items.php
1 month ago
MulticurrencyHooks.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\WcProductBundles; |
| 4 | |
| 5 | class MulticurrencyHooks implements \IWPML_Action { |
| 6 | |
| 7 | public function add_hooks() { |
| 8 | add_filter( 'wcml_price_custom_fields_filtered', [ $this, 'getPriceCustomFields' ], 10 ); |
| 9 | add_filter( 'wcml_update_custom_prices_values', [ $this, 'updateBundlesCustomPricesValues' ], 10, 2 ); |
| 10 | add_action( 'wcml_after_save_custom_prices', [ $this, 'updateBundlesBasePrice' ], 10, 4 ); |
| 11 | } |
| 12 | |
| 13 | public function getPriceCustomFields( $customFields ) { |
| 14 | return array_merge( |
| 15 | $customFields, |
| 16 | [ |
| 17 | '_wc_pb_base_regular_price', |
| 18 | '_wc_pb_base_sale_price', |
| 19 | '_wc_pb_base_price', |
| 20 | '_wc_sw_max_price', |
| 21 | '_wc_sw_max_regular_price', |
| 22 | ] |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | public function updateBundlesCustomPricesValues( $prices, $code ) { |
| 27 | if ( isset( $_POST['_custom_regular_price'][ $code ] ) ) { |
| 28 | $prices['_wc_pb_base_regular_price'] = wc_format_decimal( $_POST['_custom_regular_price'][ $code ] ); |
| 29 | } |
| 30 | |
| 31 | if ( isset( $_POST['_custom_sale_price'][ $code ] ) ) { |
| 32 | $prices['_wc_pb_base_sale_price'] = wc_format_decimal( $_POST['_custom_sale_price'][ $code ] ); |
| 33 | } |
| 34 | |
| 35 | return $prices; |
| 36 | } |
| 37 | |
| 38 | public function updateBundlesBasePrice( $postId, $productPrice, $customPrices, $code ) { |
| 39 | if ( isset( $customPrices['_wc_pb_base_regular_price'] ) ) { |
| 40 | update_post_meta( $postId, '_wc_pb_base_price_' . $code, $productPrice ); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 |