PluginProbe
Tiered Pricing Table for WooCommerce / 2.3.4
Tiered Pricing Table for WooCommerce v2.3.4
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / src / Integrations / Plugins / WooCommerceProductAddons.php

WooCommerceProductAddons.php in Tiered Pricing Table for WooCommerce 2.3.4, at src/Integrations/Plugins/WooCommerceProductAddons.php

72 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Integrations\Plugins;
2
3 class WooCommerceProductAddons {
4
5 /**
6 * WooCommerceProductAddons constructor.
7 */
8 public function __construct() {
9 include_once ABSPATH . 'wp-admin/includes/plugin.php';
10
11 if ( is_plugin_active( 'woocommerce-product-addons/woocommerce-product-addons.php' ) ) {
12
13 add_action( 'wp_head', array( $this, 'addCompatibilityScript' ) );
14
15 add_action( 'tier_pricing_table/cart/product_cart_price', array( $this, 'addAddonsPrice' ), 10, 2 );
16 add_action( 'tier_pricing_table/cart/product_cart_price/item', array( $this, 'addAddonsPrice' ), 10, 2 );
17 }
18 }
19
20 /**
21 * Add extra addons costs to product price in cart.
22 *
23 * @param float $price
24 * @param array $cart_item
25 *
26 * @return int|mixed
27 */
28 public function addAddonsPrice( $price, $cart_item ) {
29
30 $extra_cost = 0;
31
32 if ( isset( $cart_item['addons'] ) && false != $price ) {
33 foreach ( $cart_item['addons'] as $addon ) {
34 $price_type = $addon['price_type'];
35 $addon_price = $addon['price'];
36
37 switch ( $price_type ) {
38 case 'percentage_based':
39 $extra_cost += (float) ( $cart_item['data']->get_price( 'edit' ) * ( $addon_price / 100 ) );
40 break;
41 case 'flat_fee':
42 $extra_cost += (float) ( $addon_price / $cart_item['quantity'] );
43 break;
44 default:
45 $extra_cost += (float) $addon_price;
46 break;
47 }
48 }
49
50 return $price + $extra_cost;
51 }
52
53 return $price;
54
55 }
56
57 /**
58 * Render compatibility script
59 */
60 public function addCompatibilityScript() {
61 ?>
62 <script>
63 (function ($) {
64 $(document).on('tiered_price_update', function (event, data) {
65 $('#product-addons-total').data('price', data.price);
66 });
67 })(jQuery);
68 </script>
69 <?php
70 }
71 }
72