PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.4
Tiered Pricing Table for WooCommerce v7.1.4
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 / YithMulticurrency.php

YithMulticurrency.php in Tiered Pricing Table for WooCommerce 7.1.4, at src/Integrations/Plugins/YithMulticurrency.php

82 lines 2.3 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
5 class YithMulticurrency extends PluginIntegrationAbstract {
6
7 public function run() {
8 add_filter( 'tiered_pricing_table/price/price_by_rules',
9 function ( $productPrice, $quantity, $productId, $context, $place, PricingRule $pricingRule ) {
10
11 if ( ! function_exists( 'yith_wcmcs_convert_price' ) ) {
12 return $productPrice;
13 }
14
15 if ( $pricingRule->isPercentage() ) {
16 return $productPrice;
17 }
18
19 if ( $productPrice && 'view' === $context ) {
20 return (float) yith_wcmcs_convert_price( $productPrice );
21 }
22
23 return $productPrice;
24
25 }, 10, 10 );
26
27 // Add currency dependency to variable product price
28 add_filter( 'woocommerce_get_variation_prices_hash', function ( $hash ) {
29
30 if ( ! function_exists( 'yith_wcmcs_get_current_currency' ) ) {
31 return $hash;
32 }
33
34 $currency = yith_wcmcs_get_current_currency();
35
36 if ( $currency && is_callable( array( $currency, 'get_code' ) ) ) {
37 $hash[] = $currency->get_code();
38 }
39
40 return $hash;
41 }, 10, 2 );
42
43 /**
44 * Note: deliberately NO cart-side handlers here.
45 *
46 * The tiered price reaches the cart already converted through the "price_by_rules" filter
47 * above (it runs in the "view" context, including for the cart), which mirrors the conversion
48 * snippet YITH users run today. Handing the cart a raw "edit" context price instead would
49 * leave it unconverted unless YITH filters "woocommerce_product_get_price" — the assumption
50 * that broke WPML Multicurrency in 7.1.3, so it is not repeated here.
51 */
52 }
53
54 public function getTitle(): string {
55 return 'YITH Multi Currency Switcher';
56 }
57
58 public function getIconURL(): string {
59 return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/yith-raq-icon.jpeg' );
60 }
61
62 public function getAuthorURL(): string {
63 return 'https://yithemes.com/themes/plugins/yith-multi-currency-switcher-for-woocommerce/';
64 }
65
66 public function getDescription(): string {
67 return __( 'Convert and display tiered pricing correctly when using the YITH Multi Currency Switcher for WooCommerce.', 'tier-pricing-table' );
68 }
69
70 public function getSlug(): string {
71 return 'yith-multicurrency';
72 }
73
74 public function getIntegrationCategory(): string {
75 return 'multicurrency';
76 }
77
78 protected function isActiveByDefault(): bool {
79 return true;
80 }
81 }
82