PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 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 All 91 releases
tier-pricing-table / src / Integrations / Plugins / ProductBundles.php

ProductBundles.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Integrations/Plugins/ProductBundles.php

140 lines 3.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 use WC_Bundled_Item_Data;
4 use WC_Product_Bundle;
5
6 class ProductBundles extends PluginIntegrationAbstract {
7
8 public function run() {
9 add_action( 'init', function () {
10 // Bundle plugin does not exist
11 if ( ! class_exists( '\WC_Product_Bundle' ) ) {
12 return;
13 }
14
15 $this->hooks();
16 } );
17 }
18
19 protected function hooks() {
20
21 add_filter( 'tiered_pricing_table/frontend/should_wrap_price', function ( $wrap, \WC_Product $product ) {
22 return ! $product->is_type( 'bundle' );
23 }, 10, 2 );
24
25 add_filter( 'tiered_pricing_table/catalog_pricing/price_html',
26 function ( $priceHTML, $originalPriceHTML, \WC_Product $product ) {
27
28 // Do not modify pricing for bundle products
29 if ( 'bundle' === $product->get_type() ) {
30 return $originalPriceHTML;
31 }
32
33 $currentProductId = get_queried_object_id();
34 $currentProduct = wc_get_product( $currentProductId );
35
36 if ( $currentProduct instanceof WC_Product_Bundle ) {
37 foreach ( $currentProduct->get_bundled_data_items() as $dataItem ) {
38 // Do not modify prices for bundle items
39 if ( $dataItem instanceof WC_Bundled_Item_Data && $dataItem->get_product_id() === $product->get_id() ) {
40 return $originalPriceHTML;
41 }
42 }
43 }
44
45 return $priceHTML;
46 }, 10, 3 );
47
48 add_filter( 'tiered_pricing_table/supported_simple_product_types', function ( $types ) {
49 $types[] = 'bundle';
50
51 return $types;
52 }, 10, 1 );
53
54 add_action( 'wp_head', function () {
55 if ( is_product() ) {
56
57 $currentProductId = get_queried_object_id();
58 $product = wc_get_product( $currentProductId );
59
60 if ( $product->get_type() === 'bundle' ) {
61 ?>
62 <script>
63
64 var TieredPricingBundlesIntegration = function () {
65 this.bundle = null;
66
67 jQuery(document).on('woocommerce-product-bundle-initializing', (function (event, bundle) {
68 this.bundle = bundle;
69 }).bind(this));
70
71 jQuery('.tpt__tiered-pricing').on('tiered_price_update', (function (event, data) {
72
73 this.bundle.price_data.base_regular_price = data.price;
74 this.bundle.price_data.base_price = data.price;
75
76 if (this.bundle.is_initialized) {
77 this.bundle.dirty_subtotals = true;
78 this.bundle.update_totals();
79 }
80 }).bind(this));
81 }
82
83 document.tieredPricingBundlesIntegration = new TieredPricingBundlesIntegration();
84
85 </script>
86
87 <?php
88 }
89 }
90 } );
91
92 add_filter( 'tiered_pricing_table/services/pricing/override_zero_prices', '__return_false' );
93
94 add_filter( 'tiered_pricing_table/manual_created_orders/modify_item_price', function ( $modify, $item ) {
95 if ( ! $modify ) {
96 return false;
97 }
98
99 if ( ! ( $item instanceof \WC_Order_Item_Product ) ) {
100 return $modify;
101 }
102
103 if ( function_exists( 'wc_pb_is_bundled_order_item' ) ) {
104 if ( wc_pb_is_bundled_order_item( $item ) ) {
105 return false;
106 }
107 } elseif ( ! empty( $item->get_meta( '_bundled_by', true ) ) || ! empty( $item->get_meta( 'bundled_by', true ) ) ) {
108 return false;
109 }
110
111 return $modify;
112 }, 10, 2 );
113 }
114
115 public function getAuthorURL(): string {
116 return 'https://woocommerce.com/products/product-bundles/';
117 }
118
119 public function getIconURL(): string {
120 return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/woocommerce-develop.jpeg' );
121 }
122
123 public function getTitle(): string {
124 return 'Product Bundles (by WooCommerce)';
125 }
126
127 public function getDescription(): string {
128 return __( 'Apply tiered pricing discounts correctly to WooCommerce Product Bundles.',
129 'tier-pricing-table' );
130 }
131
132 public function getSlug(): string {
133 return 'product-bundles-for-woocommerce';
134 }
135
136 public function getIntegrationCategory(): string {
137 return 'custom_product_types';
138 }
139 }
140