| 1 |
<?php namespace TierPricingTable\Integrations\Plugins; |
| 2 |
|
| 3 |
use TierPricingTable\PriceManager; |
| 4 |
use TierPricingTable\PricingRule; |
| 5 |
|
| 6 |
class WOOCS 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 |
global $WOOCS_STARTER; |
| 13 |
|
| 14 |
if ( $pricingRule->isPercentage() ) { |
| 15 |
return $productPrice; |
| 16 |
} |
| 17 |
|
| 18 |
if ( $WOOCS_STARTER && $productPrice ) { |
| 19 |
if ( 'view' === $context ) { |
| 20 |
return (float) $WOOCS_STARTER->get_actual_obj()->raw_woocommerce_price( $productPrice, |
| 21 |
wc_get_product( $productId ) ); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
return $productPrice; |
| 26 |
|
| 27 |
}, 10, 10 ); |
| 28 |
|
| 29 |
add_filter( 'tiered_pricing_table/cart/product_cart_price', |
| 30 |
function ( $price, $cartItem, $cartItemKey, $totalQuantity ) { |
| 31 |
global $WOOCS_STARTER; |
| 32 |
|
| 33 |
if ( $WOOCS_STARTER && $price ) { |
| 34 |
return PriceManager::getPriceByRules( $totalQuantity, $cartItem['data']->get_id(), 'edit', 'cart', |
| 35 |
false ); |
| 36 |
} |
| 37 |
|
| 38 |
return $price; |
| 39 |
}, 10, 4 ); |
| 40 |
|
| 41 |
add_filter( 'tiered_pricing_table/cart/recalculate_cart_item_subtotal', function ( $state ) { |
| 42 |
global $WOOCS_STARTER; |
| 43 |
|
| 44 |
if ( $WOOCS_STARTER ) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
return $state; |
| 49 |
} ); |
| 50 |
} |
| 51 |
|
| 52 |
public function getTitle(): string { |
| 53 |
return 'WooCommerce Currency Switcher (FOX)'; |
| 54 |
} |
| 55 |
|
| 56 |
public function getIconURL(): string { |
| 57 |
return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/fox-icon.png' ); |
| 58 |
} |
| 59 |
|
| 60 |
public function getAuthorURL(): string { |
| 61 |
return 'https://wordpress.org/plugins/woocommerce-currency-switcher/'; |
| 62 |
} |
| 63 |
|
| 64 |
public function getDescription(): string { |
| 65 |
return __( 'Convert and display tiered pricing correctly when using the FOX WooCommerce Currency Switcher.', 'tier-pricing-table' ); |
| 66 |
} |
| 67 |
|
| 68 |
public function getSlug(): string { |
| 69 |
return 'woocs'; |
| 70 |
} |
| 71 |
|
| 72 |
public function getIntegrationCategory(): string { |
| 73 |
return 'multicurrency'; |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|