OrderItems
1 week ago
Factory.php
1 week ago
MulticurrencyHooks.php
1 week ago
class-wcml-table-rate-shipping.php
1 week ago
MulticurrencyHooks.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\TableRateShipping; |
| 4 | |
| 5 | class MulticurrencyHooks implements \IWPML_Action { |
| 6 | |
| 7 | public $woocommerce_wpml; |
| 8 | |
| 9 | public $multicurrency; |
| 10 | |
| 11 | public function __construct( \woocommerce_wpml $woocommerce_wpml, \WCML_Multi_Currency $multicurrency ) { |
| 12 | $this->woocommerce_wpml = $woocommerce_wpml; |
| 13 | $this->multicurrency = $multicurrency; |
| 14 | } |
| 15 | |
| 16 | public function add_hooks() { |
| 17 | if ( version_compare( constant( 'TABLE_RATE_SHIPPING_VERSION' ), '3.0.11', '<' ) ) { |
| 18 | add_filter( 'woocommerce_table_rate_query_rates_args', [ $this, 'filterQueryRatesArgs' ] ); |
| 19 | } |
| 20 | |
| 21 | add_filter( 'woocommerce_table_rate_package_row_base_price', [ $this, 'filterProductBasePrice' ], 10, 3 ); |
| 22 | } |
| 23 | |
| 24 | public function filterQueryRatesArgs( $args ) { |
| 25 | if ( isset( $args['price'] ) && wcml_get_woocommerce_currency_option() !== $this->multicurrency->get_client_currency() ) { |
| 26 | $args['price'] = $this->multicurrency->prices->unconvert_price_amount( $args['price'] ); |
| 27 | } |
| 28 | |
| 29 | return $args; |
| 30 | } |
| 31 | |
| 32 | public function filterProductBasePrice( $rowBasePrice, $product, $quantity ) { |
| 33 | if ( ( $product instanceof \WC_Product ) && wcml_get_woocommerce_currency_option() !== $this->multicurrency->get_client_currency() ) { |
| 34 | $rowBasePrice = $this->woocommerce_wpml->products->get_product_price_from_db( $product->get_id() ); |
| 35 | $rowBasePrice *= $quantity; |
| 36 | } |
| 37 | |
| 38 | return $rowBasePrice; |
| 39 | } |
| 40 | |
| 41 | } |
| 42 |