PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.1.0
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 6.1.0, at src/Integrations/Plugins/ProductBundles.php

120 lines 3.2 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
95 public function getAuthorURL(): string {
96 return 'https://woocommerce.com/products/product-bundles/';
97 }
98
99 public function getIconURL(): string {
100 return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/woocommerce-develop.jpeg' );
101 }
102
103 public function getTitle(): string {
104 return __( 'Product Bundles (by WooCommerce)', 'tier-pricing-table' );
105 }
106
107 public function getDescription(): string {
108 return __( 'Integration provides compatibility with Product Bundles for WooCommerce to support bundle product type.',
109 'tier-pricing-table' );
110 }
111
112 public function getSlug(): string {
113 return 'product-bundles-for-woocommerce';
114 }
115
116 public function getIntegrationCategory(): string {
117 return 'custom_product_types';
118 }
119 }
120