PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.1
Tiered Pricing Table for WooCommerce v7.1.1
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Integrations / Plugins / WPMLMulticurrency.php

WPMLMulticurrency.php in Tiered Pricing Table for WooCommerce 7.1.1, at src/Integrations/Plugins/WPMLMulticurrency.php

92 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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