| 1 |
<?php namespace TierPricingTable\Integrations\Plugins; |
| 2 |
|
| 3 |
use TierPricingTable\PricingRule; |
| 4 |
use woocommerce_wpml; |
| 5 |
|
| 6 |
class WPMLMulticurrency extends PluginIntegrationAbstract { |
| 7 |
|
| 8 |
public function run() { |
| 9 |
|
| 10 |
add_filter( 'tiered_pricing_table/price/price_by_rules', function ( |
| 11 |
$productPrice, |
| 12 |
$quantity, |
| 13 |
$productId, |
| 14 |
$context, |
| 15 |
$place, |
| 16 |
PricingRule $pricingRule |
| 17 |
) { |
| 18 |
|
| 19 |
/** |
| 20 |
* Clarifying type |
| 21 |
* |
| 22 |
* @var woocommerce_wpml $woocommerce_wpml |
| 23 |
*/ global $woocommerce_wpml; |
| 24 |
|
| 25 |
if ( $pricingRule->isPercentage() || ! $productPrice || ! $woocommerce_wpml ) { |
| 26 |
return $productPrice; |
| 27 |
} |
| 28 |
|
| 29 |
if ( ! $woocommerce_wpml->multi_currency || ! method_exists( $woocommerce_wpml->multi_currency, |
| 30 |
'get_client_currency' ) ) { |
| 31 |
return $productPrice; |
| 32 |
} |
| 33 |
|
| 34 |
$currentCurrency = $woocommerce_wpml->multi_currency->get_client_currency(); |
| 35 |
|
| 36 |
if ( wcml_get_woocommerce_currency_option() !== $currentCurrency ) { |
| 37 |
|
| 38 |
return $woocommerce_wpml->multi_currency->prices->convert_price_amount( $productPrice, |
| 39 |
$currentCurrency ); |
| 40 |
} |
| 41 |
|
| 42 |
return $productPrice; |
| 43 |
}, 10, 10 ); |
| 44 |
|
| 45 |
add_filter( 'tiered_pricing_table/services/regular_pricing/price', function ( $newPrice ) { |
| 46 |
|
| 47 |
if ( is_null( $newPrice ) ) { |
| 48 |
return $newPrice; |
| 49 |
} |
| 50 |
|
| 51 |
global $woocommerce_wpml; |
| 52 |
|
| 53 |
if ( ! $woocommerce_wpml || ! $woocommerce_wpml->multi_currency || ! method_exists( $woocommerce_wpml->multi_currency, |
| 54 |
'get_client_currency' ) ) { |
| 55 |
return $newPrice; |
| 56 |
} |
| 57 |
|
| 58 |
$currentCurrency = $woocommerce_wpml->multi_currency->get_client_currency(); |
| 59 |
|
| 60 |
if ( wcml_get_woocommerce_currency_option() !== $currentCurrency ) { |
| 61 |
return $woocommerce_wpml->multi_currency->prices->convert_price_amount( $newPrice, $currentCurrency ); |
| 62 |
} |
| 63 |
|
| 64 |
return $newPrice; |
| 65 |
}, 10, 4 ); |
| 66 |
} |
| 67 |
|
| 68 |
public function getTitle(): string { |
| 69 |
return 'WPML Multicurrency'; |
| 70 |
} |
| 71 |
|
| 72 |
public function getIconURL(): string { |
| 73 |
return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/wpml-multicurrency-icon.png' ); |
| 74 |
} |
| 75 |
|
| 76 |
public function getAuthorURL(): string { |
| 77 |
return 'https://wpml.org/documentation/related-projects/woocommerce-multilingual/'; |
| 78 |
} |
| 79 |
|
| 80 |
public function getDescription(): string { |
| 81 |
return __( 'Convert and display tiered pricing correctly when using WPML Multicurrency.', 'tier-pricing-table' ); |
| 82 |
} |
| 83 |
|
| 84 |
public function getSlug(): string { |
| 85 |
return 'wpml_multicurrency'; |
| 86 |
} |
| 87 |
|
| 88 |
public function getIntegrationCategory(): string { |
| 89 |
return 'multicurrency'; |
| 90 |
} |
| 91 |
} |
| 92 |
|