PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.1
Tiered Pricing Table for WooCommerce v7.1.1
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 / views / frontend / tiered-pricing-table-style-2.php

tiered-pricing-table-style-2.php in Tiered Pricing Table for WooCommerce 7.1.1, at views/frontend/tiered-pricing-table-style-2.php

285 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Available variables
4 *
5 * @var PricingRule $pricing_rule
6 * @var array $price_rules
7 * @var string $pricing_type
8 * @var string $real_price
9 * @var string $product_name
10 * @var WC_Product $product
11 * @var string $id
12 * @var int $product_id
13 * @var int $minimum
14 * @var array $settings
15 */
16
17 use TierPricingTable\CalculationLogic;
18 use TierPricingTable\PriceManager;
19 use TierPricingTable\PricingRule;
20
21 if ( ! defined( 'WPINC' ) ) {
22 die;
23 }
24
25 $sale_price = $product->get_sale_price();
26
27 if ( $sale_price ) {
28 $sale_price = wc_get_price_to_display( $product, array(
29 'price' => $sale_price,
30 ) );
31 }
32
33 $regular_price = wc_get_price_to_display( $product, array(
34 'price' => $product->get_regular_price(),
35 ) );
36
37 $price = wc_get_price_to_display( $product, array(
38 'price' => $product->get_price(),
39 ) );
40
41 $price_incl_taxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
42 'price' => $real_price,
43 ) );
44
45 $price_excl_taxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
46 'price' => $real_price,
47 ) );
48
49 ?>
50
51 <?php if ( ! empty( $pricing_rule->getRules() ) ) : ?>
52 <div class="clear"></div>
53
54 <div class="tiered-pricing-wrapper">
55 <?php if ( ! empty( $settings['title'] ) ) : ?>
56 <h3 style="clear:both; margin: 20px 0; font-weight: 600;"><?php echo esc_attr( $settings['title'] ); ?></h3>
57 <?php endif; ?>
58
59 <?php do_action( 'tiered_pricing_table/tiered_pricing/before', $pricing_rule ); ?>
60
61 <?php
62 $columns = 0;
63 if ( $settings['quantity_column_title'] ) $columns++;
64 if ( $settings['discount_column_title'] ) $columns++;
65 if ( $settings['price_column_title'] ) $columns++;
66
67 // Detect custom columns via output buffering
68 ob_start();
69 do_action( 'tiered_pricing_table/tiered_pricing/header_columns', $pricing_rule );
70 $custom_head = ob_get_clean();
71 $custom_columns_count = substr_count($custom_head, '<th');
72 $columns += $custom_columns_count;
73 ?>
74
75 <div class="tiered-pricing-table tiered-pricing-table--styled tiered-pricing-table--style-2 <?php echo (isset($settings['compact_layout']) && $settings['compact_layout'] === 'yes') ? 'tiered-pricing-table--slim' : ''; ?>"
76 id="<?php echo esc_attr( $id ); ?>"
77 data-tiered-pricing-table
78 data-product-id="<?php echo esc_attr( $product_id ); ?>"
79 data-price-rules="<?php echo esc_attr( json_encode( $pricing_rule->getRules() ) ); ?>"
80 data-minimum="<?php echo esc_attr( $minimum ); ?>"
81 data-product-name="<?php echo esc_attr( $product_name ); ?>"
82 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
83 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
84 data-price="<?php echo esc_attr( $price ); ?>"
85 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
86 >
87 <div class="tiered-pricing-table-header" style="grid-template-columns: repeat(<?php echo $columns; ?>, 1fr);">
88 <?php if ( $settings['quantity_column_title'] ) : ?>
89 <div><?php echo esc_attr( $settings['quantity_column_title'] ); ?></div>
90 <?php endif; ?>
91
92 <?php if ( $settings['discount_column_title'] ) : ?>
93 <div><?php echo esc_attr( ( $settings['discount_column_title'] ) ); ?></div>
94 <?php endif; ?>
95
96 <?php if ( $settings['price_column_title'] ) : ?>
97 <div><?php echo esc_attr( $settings['price_column_title'] ); ?></div>
98 <?php endif; ?>
99
100 <?php echo str_replace(['<th', '</th>'], ['<div', '</div>'], $custom_head); ?>
101 </div>
102
103 <div class="tiered-pricing-table-body">
104 <div class="tiered-pricing-table-row tiered-pricing--active"
105 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
106 data-tiered-price="<?php echo esc_attr( $price ); ?>"
107 data-tiered-price-exclude-taxes="<?php echo esc_attr( $price_excl_taxes ); ?>"
108 data-tiered-price-include-taxes="<?php echo esc_attr( $price_incl_taxes ); ?>"
109 style="grid-template-columns: repeat(<?php echo $columns; ?>, 1fr);">
110
111 <?php if ( $settings['quantity_column_title'] ) : ?>
112 <div>
113 <?php if ( 1 >= array_keys( $pricing_rule->getRules() )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
114 <span>
115 <span class="tiered-pricing-table-row-qty">
116 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?>
117 </span>
118 <span class="tiered-pricing-table-row-qty-unit">
119 <?php echo esc_attr( ' ' . $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] ); ?>
120 </span>
121 </span>
122 <?php else : ?>
123 <span>
124 <span class="tiered-pricing-table-row-qty">
125 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $pricing_rule->getRules() )[0] - 1 ) ); ?>
126 </span>
127 <span class="tiered-pricing-table-row-qty-unit">
128 <?php echo esc_attr( ' ' . $settings['quantity_measurement_plural'] ); ?>
129 </span>
130 </span>
131 <?php endif; ?>
132
133 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $minimum, array(
134 'id' => $id,
135 'style' => 'default',
136 ) ); ?>
137 </div>
138 <?php endif; ?>
139
140 <?php if ( $settings['discount_column_title'] ) : ?>
141
142 <?php
143 $discountAmount = 0;
144 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
145 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
146 $product->get_sale_price() );
147 }
148 ?>
149
150 <div>
151 <?php if ( $discountAmount > 0 ) : ?>
152 <span class="tiered-pricing-table-row-discount"><?php echo esc_attr( round( $discountAmount, 2 ) ); ?> %</span>
153 <?php else : ?>
154 <span class="tiered-pricing-table-row-discount--empty">—</span>
155 <?php endif; ?>
156 </div>
157 <?php endif; ?>
158
159 <?php if ( $settings['price_column_title'] ) : ?>
160 <div class="tiered-pricing-table-row-price">
161 <?php
162 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ),
163 array( 'price' => $real_price, ) ) ) );
164 ?>
165 </div>
166 <?php endif; ?>
167
168 <?php
169 ob_start();
170 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, null );
171 $custom_cols = ob_get_clean();
172 echo str_replace(['<td', '</td>'], ['<div', '</div>'], $custom_cols);
173 ?>
174 </div>
175
176 <?php $iterator = new ArrayIterator( $pricing_rule->getRules() ); ?>
177
178 <?php while ( $iterator->valid() ) : ?>
179 <?php
180 $currentPrice = $iterator->current();
181 $currentQuantity = $iterator->key();
182
183 $iterator->next();
184
185 if ( $pricing_rule->getType() === 'percentage' ) {
186 $discountAmount = $currentPrice;
187 } else {
188 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
189 $pricing_rule->getTierPrice( $currentQuantity, false ) );
190 }
191
192 $quantity = number_format_i18n( $currentQuantity );
193
194 if ( $iterator->valid() ) {
195
196 if ( intval( $iterator->key() - 1 != $currentQuantity ) && 'range' === $settings['quantity_type'] ) {
197 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
198 }
199
200 } else {
201 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
202 $currentQuantity, $pricing_rule, 'table' );
203 }
204
205 $quantityUnit = $settings['quantity_measurement_plural'];
206
207 $currentProductPrice = $pricing_rule->getTierPrice( $currentQuantity );
208
209 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
210 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
211 ) );
212
213 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
214 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
215 ) );
216
217 ?>
218 <div class="tiered-pricing-table-row" data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
219 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
220 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
221 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>"
222 style="grid-template-columns: repeat(<?php echo $columns; ?>, 1fr);">
223
224 <?php if ( $settings['quantity_column_title'] ) : ?>
225 <div>
226 <span class="tiered-pricing-table-row-qty"><?php echo esc_attr( $quantity ); ?></span>
227 <span class="tiered-pricing-table-row-qty-unit"> <?php echo esc_attr( $quantityUnit ); ?></span>
228 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $currentQuantity,
229 array(
230 'id' => $id,
231 'style' => 'default',
232 ) ); ?>
233 </div>
234 <?php endif; ?>
235
236 <?php if ( $settings['discount_column_title'] ) : ?>
237 <div>
238 <?php if ( $discountAmount > 0 ) : ?>
239 <span class="tiered-pricing-table-row-discount"><?php echo esc_attr( round( $discountAmount, 2 ) ); ?> %</span>
240 <?php else : ?>
241 <span class="tiered-pricing-table-row-discount--empty">—</span>
242 <?php endif; ?>
243 </div>
244 <?php endif; ?>
245
246 <?php if ( $settings['price_column_title'] ) : ?>
247 <div class="tiered-pricing-table-row-price">
248 <?php
249 echo wp_kses_post( wc_price( $pricing_rule->getTierPrice( $currentQuantity ) ) );
250 ?>
251 </div>
252 <?php endif; ?>
253
254 <?php
255 ob_start();
256 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, $currentQuantity );
257 $custom_cols = ob_get_clean();
258 echo str_replace(['<td', '</td>'], ['<div', '</div>'], $custom_cols);
259 ?>
260 </div>
261
262 <?php endwhile; ?>
263 <?php do_action( 'tiered_pricing_table/tiered_pricing/rows', $pricing_rule, $settings, 'tiered-pricing-table-style-2' ); ?>
264 <?php do_action( 'tiered_pricing_table/table/tfoot', $pricing_rule, $settings, 'tiered-pricing-table-style-2' ); ?>
265 </div>
266 </div>
267
268 <?php do_action( 'tiered_pricing_table/tiered_pricing/after', $pricing_rule, $product_id ); ?>
269 </div>
270
271 <style>
272 <?php
273 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
274 echo esc_attr('#' . $id) . ' .tiered-pricing-table-row { cursor: pointer; }';
275 echo esc_attr('#' . $id) . ' .tiered-pricing-table-row:not(.tiered-pricing--active):hover { box-shadow: 0 6px 12px rgba(0,0,0,0.05); transform: translateY(-2px); border-color: #e5e7eb; }';
276 }
277 ?>
278
279 <?php echo esc_attr('#' . $id); ?> .tiered-pricing--active {
280 border: 2px solid <?php echo esc_attr($settings['active_tier_color']); ?> !important;
281 box-shadow: 0 4px 12px <?php echo esc_attr($settings['active_tier_color']); ?>20 !important;
282 }
283 </style>
284 <?php endif; ?>
285