| 1 |
<?php namespace TierPricingTable\Integrations\Plugins; |
| 2 |
|
| 3 |
use TierPricingTable\PriceManager; |
| 4 |
use TierPricingTable\PricingRule; |
| 5 |
|
| 6 |
class Curcy extends PluginIntegrationAbstract { |
| 7 |
|
| 8 |
public function run() { |
| 9 |
add_filter( 'tiered_pricing_table/price/price_by_rules', |
| 10 |
function ( $productPrice, $quantity, $productId, $context, $place, PricingRule $pricingRule ) { |
| 11 |
|
| 12 |
if ( ! function_exists( 'wmc_get_price' ) ) { |
| 13 |
return $productPrice; |
| 14 |
} |
| 15 |
|
| 16 |
if ( $pricingRule->isPercentage() ) { |
| 17 |
return $productPrice; |
| 18 |
} |
| 19 |
|
| 20 |
if ( $productPrice && 'view' === $context ) { |
| 21 |
return wmc_get_price( $productPrice ); |
| 22 |
} |
| 23 |
|
| 24 |
return $productPrice; |
| 25 |
|
| 26 |
}, 10, 10 ); |
| 27 |
|
| 28 |
add_filter( 'tiered_pricing_table/cart/product_cart_price', |
| 29 |
function ( $price, $cartItem, $cartItemKey, $totalQuantity ) { |
| 30 |
|
| 31 |
if ( ! function_exists( 'wmc_get_price' ) ) { |
| 32 |
return $price; |
| 33 |
} |
| 34 |
|
| 35 |
if ( $price ) { |
| 36 |
return PriceManager::getPriceByRules( $totalQuantity, $cartItem['data']->get_id(), 'edit', 'cart', |
| 37 |
false ); |
| 38 |
} |
| 39 |
|
| 40 |
return $price; |
| 41 |
}, 10, 4 ); |
| 42 |
|
| 43 |
add_filter( 'tiered_pricing_table/cart/recalculate_cart_item_subtotal', function ( $state ) { |
| 44 |
if ( function_exists( 'wmc_get_price' ) ) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
return $state; |
| 49 |
} ); |
| 50 |
|
| 51 |
// Add currency dependency to variable product price |
| 52 |
add_filter( 'woocommerce_get_variation_prices_hash', function ( $hash ) { |
| 53 |
|
| 54 |
if ( ! class_exists( 'WOOMULTI_CURRENCY_F_Data' ) ) { |
| 55 |
return $hash; |
| 56 |
} |
| 57 |
|
| 58 |
$setting = \WOOMULTI_CURRENCY_F_Data::get_ins(); |
| 59 |
|
| 60 |
$hash[] = $setting->get_current_currency(); |
| 61 |
|
| 62 |
return $hash; |
| 63 |
}, 10, 2 ); |
| 64 |
} |
| 65 |
|
| 66 |
public function getTitle(): string { |
| 67 |
return __( 'CURCY Multicurrency', 'tier-pricing-table' ); |
| 68 |
} |
| 69 |
|
| 70 |
public function getIconURL(): string { |
| 71 |
return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/curcy-icon.png' ); |
| 72 |
} |
| 73 |
|
| 74 |
public function getAuthorURL(): string { |
| 75 |
return 'https://ru.wordpress.org/plugins/woo-multi-currency/'; |
| 76 |
} |
| 77 |
|
| 78 |
public function getDescription(): string { |
| 79 |
return __( 'Make the tiered pricing properly work with multiple currencies.', 'tier-pricing-table' ); |
| 80 |
} |
| 81 |
|
| 82 |
public function getSlug(): string { |
| 83 |
return 'curcy'; |
| 84 |
} |
| 85 |
|
| 86 |
public function getIntegrationCategory(): string { |
| 87 |
return 'multicurrency'; |
| 88 |
} |
| 89 |
|
| 90 |
protected function isActiveByDefault(): bool { |
| 91 |
return true; |
| 92 |
} |
| 93 |
} |
| 94 |
|