| 1 |
<?php namespace TierPricingTable\Integrations\Plugins; |
| 2 |
|
| 3 |
use TierPricingTable\PriceManager; |
| 4 |
use TierPricingTable\PricingRule; |
| 5 |
|
| 6 |
class WCCS extends PluginIntegrationAbstract { |
| 7 |
|
| 8 |
public function run() { |
| 9 |
|
| 10 |
add_filter( 'tiered_pricing_table/price/price_by_rules', |
| 11 |
function ( $product_price, $quantity, $product_id, $context, $place, PricingRule $pricingRule ) { |
| 12 |
|
| 13 |
global $WCCS; |
| 14 |
|
| 15 |
// Percentage tiers are derived from the product's 'view' price, which WCCS has already converted. |
| 16 |
// Converting again here would double-convert the price. |
| 17 |
if ( $pricingRule->isPercentage() ) { |
| 18 |
return $product_price; |
| 19 |
} |
| 20 |
|
| 21 |
if ( $WCCS && $product_price ) { |
| 22 |
|
| 23 |
$product = wc_get_product( $product_id ); |
| 24 |
|
| 25 |
if ( 'view' === $context && $product ) { |
| 26 |
return $WCCS->wccs_custom_price( $product_price, $product ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
return $product_price; |
| 31 |
|
| 32 |
}, 10, 10 ); |
| 33 |
|
| 34 |
add_filter( 'tiered_pricing_table/cart/product_cart_price', |
| 35 |
function ( $price, $cartItem, $cartItemKey, $totalQuantity ) { |
| 36 |
|
| 37 |
global $WCCS; |
| 38 |
|
| 39 |
if ( ! $WCCS ) { |
| 40 |
return $price; |
| 41 |
} |
| 42 |
|
| 43 |
if ( $price ) { |
| 44 |
return PriceManager::getPriceByRules( $totalQuantity, $cartItem['data']->get_id(), 'edit', 'cart', |
| 45 |
false ); |
| 46 |
} |
| 47 |
|
| 48 |
return $price; |
| 49 |
}, 10, 4 ); |
| 50 |
|
| 51 |
add_filter( 'tiered_pricing_table/cart/recalculate_cart_item_subtotal', function ( $state ) { |
| 52 |
global $WCCS; |
| 53 |
|
| 54 |
if ( $WCCS ) { |
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
return $state; |
| 59 |
} ); |
| 60 |
} |
| 61 |
|
| 62 |
public function getTitle(): string { |
| 63 |
return 'WooCommerce Currency Switcher by WP Experts (WCCS)'; |
| 64 |
} |
| 65 |
|
| 66 |
public function getDescription(): string { |
| 67 |
return __( 'Convert and display tiered pricing correctly when using the WooCommerce Currency Switcher by WP Experts.', 'tier-pricing-table' ); |
| 68 |
} |
| 69 |
|
| 70 |
public function getIconURL(): string { |
| 71 |
return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/wccs-icon.png' ); |
| 72 |
} |
| 73 |
|
| 74 |
public function getAuthorURL(): string { |
| 75 |
return 'https://woocommerce.com/products/currency-switcher-for-woocommerce/'; |
| 76 |
} |
| 77 |
|
| 78 |
public function getSlug(): string { |
| 79 |
return 'wccs'; |
| 80 |
} |
| 81 |
|
| 82 |
public function getIntegrationCategory(): string { |
| 83 |
return 'multicurrency'; |
| 84 |
} |
| 85 |
} |
| 86 |
|