Factory.php
2 weeks ago
MulticurrencyHooks.php
2 weeks ago
class-wcml-mix-and-match-products.php
2 weeks ago
MulticurrencyHooks.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\WcMixAndMatch; |
| 4 | |
| 5 | class MulticurrencyHooks implements \IWPML_Action { |
| 6 | |
| 7 | public function add_hooks() { |
| 8 | add_filter( 'wcml_price_custom_fields_filtered', [ $this, 'get_price_custom_fields' ], 10 ); |
| 9 | add_filter( 'wcml_update_custom_prices_values', [ $this, 'update_container_custom_prices_values' ], 10, 2 ); |
| 10 | add_filter( 'wcml_after_save_custom_prices', [ $this, 'update_container_base_price' ], 10, 4 ); |
| 11 | } |
| 12 | |
| 13 | public function get_price_custom_fields( $custom_fields ) { |
| 14 | return array_merge( |
| 15 | $custom_fields, |
| 16 | [ |
| 17 | '_mnm_base_regular_price', |
| 18 | '_mnm_base_sale_price', |
| 19 | '_mnm_base_price', |
| 20 | '_mnm_max_price', |
| 21 | '_mnm_max_regular_price', |
| 22 | ] |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | public function update_container_custom_prices_values( $prices, $code ) { |
| 27 | foreach ( [ |
| 28 | '_custom_regular_price' => '_mnm_base_regular_price', |
| 29 | '_custom_sale_price' => '_mnm_base_sale_price', |
| 30 | ] as $wc_price => $custom_price ) { |
| 31 | if ( isset( $_POST[ $wc_price ][ $code ] ) ) { |
| 32 | $prices[ $custom_price ] = wc_format_decimal( $_POST[ $wc_price ][ $code ] ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return $prices; |
| 37 | } |
| 38 | |
| 39 | public function update_container_base_price( $post_id, $product_price, $custom_prices, $code ) { |
| 40 | |
| 41 | if ( isset( $custom_prices['_mnm_base_regular_price'] ) ) { |
| 42 | update_post_meta( $post_id, '_mnm_base_price_' . $code, $product_price ); |
| 43 | } |
| 44 | |
| 45 | } |
| 46 | |
| 47 | } |
| 48 |