| 1 |
<?php namespace TierPricingTable\Integrations\Plugins; |
| 2 |
|
| 3 |
class WCPA extends PluginIntegrationAbstract { |
| 4 |
|
| 5 |
public function addAddonsPriceToItem( $price, $cart_item ) { |
| 6 |
|
| 7 |
if ( $price && ! empty( $cart_item['wcpa_options_price_start'] ) ) { |
| 8 |
$price += $cart_item['wcpa_options_price_start']; |
| 9 |
} |
| 10 |
|
| 11 |
return $price; |
| 12 |
} |
| 13 |
|
| 14 |
public function getTitle(): string { |
| 15 |
return 'WooCommerce Custom Product Addons (WCPA) by Acowebs'; |
| 16 |
} |
| 17 |
|
| 18 |
public function getDescription(): string { |
| 19 |
return __( 'Calculate tiered pricing accurately when custom product add-ons are selected.', 'tier-pricing-table' ); |
| 20 |
} |
| 21 |
|
| 22 |
public function getSlug(): string { |
| 23 |
return 'wcpa'; |
| 24 |
} |
| 25 |
|
| 26 |
public function getAuthorURL(): string { |
| 27 |
return 'https://wordpress.org/plugins/woo-custom-product-addons/'; |
| 28 |
} |
| 29 |
|
| 30 |
public function getIconURL(): string { |
| 31 |
return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/wcpa-icon.png' ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Render compatibility script |
| 36 |
*/ |
| 37 |
public function addCompatibilityScript() { |
| 38 |
|
| 39 |
if ( ! is_product() ) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
?> |
| 44 |
<script> |
| 45 |
// Tiered Pricing WOOCS Compatibility |
| 46 |
(function ($) { |
| 47 |
$('.tpt__tiered-pricing').on('tiered_price_update', function (event, data) { |
| 48 |
$.each($('.wcpa_form_outer'), function (i, el) { |
| 49 |
var $el = $(el); |
| 50 |
var product = $el.data('product'); |
| 51 |
|
| 52 |
if (product) { |
| 53 |
product.wc_product_price = data.price; |
| 54 |
$(el).data('product', product); |
| 55 |
} |
| 56 |
}); |
| 57 |
}); |
| 58 |
})(jQuery); |
| 59 |
</script> |
| 60 |
<?php |
| 61 |
} |
| 62 |
|
| 63 |
public function run() { |
| 64 |
|
| 65 |
add_action( 'wp_head', array( $this, 'addCompatibilityScript' ) ); |
| 66 |
|
| 67 |
|
| 68 |
add_filter( 'tiered_pricing_table/cart/product_cart_price', array( $this, 'addAddonsPriceToItem' ), 20, 2 ); |
| 69 |
add_filter( 'tiered_pricing_table/cart/product_cart_regular_price/item', array( |
| 70 |
$this, |
| 71 |
'addAddonsPriceToItem', |
| 72 |
), 20, 2 ); |
| 73 |
add_filter( 'tiered_pricing_table/cart/product_cart_price/item', array( |
| 74 |
$this, |
| 75 |
'addAddonsPriceToItem', |
| 76 |
), 20, 2 ); |
| 77 |
add_filter( 'tiered_pricing_table/cart/product_cart_old_price', array( $this, 'addAddonsPriceToItem' ), 20, 2 ); |
| 78 |
} |
| 79 |
|
| 80 |
public function getIntegrationCategory(): string { |
| 81 |
return 'product_addons'; |
| 82 |
} |
| 83 |
} |
| 84 |
|