| 1 |
<?php namespace TierPricingTable\Integrations\Plugins; |
| 2 |
|
| 3 |
class WooCommerceDeposits extends PluginIntegrationAbstract { |
| 4 |
|
| 5 |
public function getTitle(): string { |
| 6 |
return __( 'WooCommerce Deposits (by WooCommerce)', 'tier-pricing-table' ); |
| 7 |
} |
| 8 |
|
| 9 |
public function getDescription(): string { |
| 10 |
return __( 'Make tiered pricing properly work with deposit purchases.', 'tier-pricing-table' ); |
| 11 |
} |
| 12 |
|
| 13 |
public function getSlug(): string { |
| 14 |
return 'woocommerce-deposits'; |
| 15 |
} |
| 16 |
|
| 17 |
public function getAuthorURL(): string { |
| 18 |
return 'https://woocommerce.com/products/woocommerce-deposits/'; |
| 19 |
} |
| 20 |
|
| 21 |
public function getIconURL(): string { |
| 22 |
return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/woocommerce-develop.jpeg' ); |
| 23 |
} |
| 24 |
|
| 25 |
public function run() { |
| 26 |
add_filter( 'tiered_pricing_table/cart/product_cart_price', function ( $new_price, $cart_item, $key ) { |
| 27 |
|
| 28 |
if ( $new_price ) { |
| 29 |
// WooCommerce Deposit |
| 30 |
$cart = wc()->cart; |
| 31 |
|
| 32 |
if ( isset( $cart->cart_contents[ $key ]['full_amount'] ) ) { |
| 33 |
|
| 34 |
$depositPercentage = 1 / ( $cart->cart_contents[ $key ]['full_amount'] / $cart->cart_contents[ $key ]['deposit_amount'] ); |
| 35 |
|
| 36 |
$cart->cart_contents[ $key ]['full_amount'] = $new_price; |
| 37 |
$cart->cart_contents[ $key ]['deposit_amount'] = $cart->cart_contents[ $key ]['full_amount'] * $depositPercentage; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return $new_price; |
| 42 |
|
| 43 |
}, 10, 3 ); |
| 44 |
} |
| 45 |
|
| 46 |
public function getIntegrationCategory(): string { |
| 47 |
return 'custom_product_types'; |
| 48 |
} |
| 49 |
} |
| 50 |
|