PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.0
Tiered Pricing Table for WooCommerce v8.1.0
8.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 All 92 releases
tier-pricing-table / views / frontend / tiered-pricing-options-style-6.php

tiered-pricing-options-style-6.php in Tiered Pricing Table for WooCommerce 8.1.0, at views/frontend/tiered-pricing-options-style-6.php

375 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use TierPricingTable\CalculationLogic;
4 use TierPricingTable\PriceManager;
5 use TierPricingTable\PricingTable;
6 use TierPricingTable\PricingRule;
7 use TierPricingTable\Settings\Settings;
8 if ( !defined( 'WPINC' ) ) {
9 die;
10 }
11 /**
12 * Available variables
13 *
14 * @var array $price_rules
15 * @var PricingRule $pricing_rule
16 * @var string $real_price
17 * @var string $product_name
18 * @var string $pricing_type
19 * @var WC_Product $product
20 * @var string $id
21 * @var int $product_id
22 * @var int $minimum
23 * @var array $settings
24 */
25 $sale_price = $product->get_sale_price();
26 if ( $sale_price ) {
27 $sale_price = wc_get_price_to_display( $product, array(
28 'price' => $sale_price,
29 ) );
30 }
31 $regular_price = wc_get_price_to_display( $product, array(
32 'price' => $product->get_regular_price(),
33 ) );
34 $price = wc_get_price_to_display( $product, array(
35 'price' => $product->get_price(),
36 ) );
37 if ( !function_exists( 'tptParseOptionText' ) ) {
38 function tptParseOptionText(
39 $text,
40 $quantity,
41 $discount = null,
42 $base_unit_name = null
43 ) {
44 return strtr( $text, array(
45 '{tp_quantity}' => $quantity,
46 '{tp_discount}' => ( !is_null( $discount ) ? round( (float) $discount, \TierPricingTable\PricingTable::discountDecimals( (float) $discount ) ) : $discount ),
47 '{tp_rounded_discount}' => ( !is_null( $discount ) ? round( $discount ) : 0 ),
48 '{tp_base_unit_name}' => $base_unit_name,
49 ) );
50 }
51
52 }
53 // discount of every tier (percent), for the biggest discount
54 $tierDiscounts = array();
55 foreach ( $price_rules as $tierQuantity => $tierPrice ) {
56 $tierDiscounts[$tierQuantity] = ( 'percentage' === $pricing_type ? (float) $tierPrice : (float) PriceManager::calculateDiscount( ( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price() ), $pricing_rule->getTierPrice( $tierQuantity, false ) ) );
57 }
58 $maxDiscount = ( $tierDiscounts ? max( $tierDiscounts ) : 0 );
59 if ( !empty( $price_rules ) ) {
60 ?>
61
62 <div class="tiered-pricing-wrapper">
63 <?php
64 if ( !empty( $settings['title'] ) ) {
65 ?>
66 <h3 style="clear:both; margin: 20px 0;"><?php
67 echo esc_attr( $settings['title'] );
68 ?></h3>
69 <?php
70 }
71 ?>
72
73 <div class="tiered-pricing-options tiered-pricing-options--styled tiered-pricing-options--style-6 <?php
74 echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ? 'tiered-pricing-options--slim' : '' );
75 ?>"
76
77 <?php
78 echo PricingTable::layoutStyleAttribute( $settings );
79 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper
80 ?>
81 id="<?php
82 echo esc_attr( $id );
83 ?>"
84 data-product-id="<?php
85 echo esc_attr( $product_id );
86 ?>"
87 data-price-rules="<?php
88 echo esc_attr( htmlspecialchars( json_encode( $price_rules ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) );
89 ?>"
90 data-minimum="<?php
91 echo esc_attr( $minimum );
92 ?>"
93 data-product-name="<?php
94 echo esc_attr( $product_name );
95 ?>"
96 data-regular-price="<?php
97 echo esc_attr( $regular_price );
98 ?>"
99 data-sale-price="<?php
100 echo esc_attr( $sale_price );
101 ?>"
102 data-price="<?php
103 echo esc_attr( $price );
104 ?>"
105 data-product-price-suffix="<?php
106 echo esc_attr( $product->get_price_suffix() );
107 ?>"
108 >
109 <?php
110 $tptTierRows = array();
111 ob_start();
112 ?>
113 <?php
114 $discountAmount = 0;
115 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
116 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(), $product->get_sale_price() );
117 }
118 if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) {
119 $quantity = esc_attr( number_format_i18n( $minimum ) . ' ' );
120 $baseUnitName = ( $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] );
121 } else {
122 $quantity = esc_attr( number_format_i18n( $minimum ) . ' - ' . number_format_i18n( array_keys( $price_rules )[0] - 1 ) . ' ' );
123 $baseUnitName = $settings['quantity_measurement_plural'];
124 }
125 $optionText = ( $discountAmount > 0 ? tptParseOptionText(
126 $settings['options_option_text'],
127 $quantity,
128 round( $discountAmount, 2 ),
129 $baseUnitName
130 ) : tptParseOptionText(
131 $settings['options_default_option_text'],
132 $quantity,
133 null,
134 $baseUnitName
135 ) );
136 ?>
137 <div class="tiered-pricing-option tiered-pricing--active tiered-pricing-option--default"
138 data-tiered-quantity="<?php
139 echo esc_attr( $minimum );
140 ?>"
141 data-tiered-price="<?php
142 echo esc_attr( $price );
143 ?>"
144 data-tiered-price-exclude-taxes="<?php
145 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
146 'price' => $real_price,
147 ) ) );
148 ?>"
149 data-tiered-price-include-taxes="<?php
150 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
151 'price' => $real_price,
152 ) ) );
153 ?>"
154 >
155 <div class="tiered-pricing-option__checkbox">
156 <div class="tiered-pricing-option-checkbox tiered-pricing-option-checkbox--active"></div>
157 </div>
158 <div class="tiered-pricing-option__quantity">
159 <?php
160 echo wp_kses_post( $optionText );
161 ?>
162 <?php
163 do_action(
164 'tiered_pricing_table/options/label',
165 $pricing_rule,
166 $minimum,
167 array(
168 'id' => $id,
169 'style' => '6',
170 )
171 );
172 ?>
173 </div>
174 <div class="tiered-pricing-option__pricing">
175 <div class="tiered-pricing-option-price">
176 <?php
177 if ( $discountAmount > 0 ) {
178 ?>
179 <div class="tiered-pricing-option-price__original"><del><?php
180 echo wp_kses_post( wc_price( $regular_price ) );
181 ?></del></div>
182 <?php
183 }
184 ?>
185 <div class="tiered-pricing-option-price__discounted"><?php
186 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
187 'price' => $real_price,
188 ) ) ) );
189 ?></div>
190 <?php
191 if ( $settings['show_discount_column'] && $discountAmount > 0 ) {
192 ?>
193 <span class="tiered-pricing-option__discount-label">(<?php
194 echo wp_kses_post( PricingTable::formatDiscount(
195 $discountAmount,
196 $pricing_rule,
197 $product,
198 null,
199 $settings,
200 'off'
201 ) );
202 ?>)</span>
203 <?php
204 }
205 ?>
206 </div>
207 <?php
208 ?>
209 </div>
210 </div>
211 <?php
212 $tptTierRows[] = ob_get_clean();
213 ?>
214
215 <?php
216 $iterator = new ArrayIterator($price_rules);
217 ?>
218
219 <?php
220 while ( $iterator->valid() ) {
221 ob_start();
222 ?>
223 <?php
224 $currentPrice = $iterator->current();
225 $currentQuantity = $iterator->key();
226 $discountAmount = $tierDiscounts[$currentQuantity];
227 $iterator->next();
228 if ( $iterator->valid() ) {
229 $quantity = number_format_i18n( $currentQuantity );
230 if ( (int) $iterator->key() - 1 !== (int) $currentQuantity && 'range' === $settings['quantity_type'] ) {
231 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
232 }
233 } else {
234 $quantity = number_format_i18n( $currentQuantity );
235 $quantity .= apply_filters(
236 'tiered_pricing_table/tiered_pricing/last_tier_postfix',
237 '+',
238 $currentQuantity,
239 $pricing_rule,
240 'blocks'
241 );
242 }
243 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
244 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
245 'price' => PriceManager::getPriceByRules(
246 $currentQuantity,
247 $product_id,
248 null,
249 null,
250 false
251 ),
252 ) );
253 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
254 'price' => PriceManager::getPriceByRules(
255 $currentQuantity,
256 $product_id,
257 null,
258 null,
259 false
260 ),
261 ) );
262 $optionText = tptParseOptionText(
263 $settings['options_option_text'],
264 $quantity,
265 round( $discountAmount, 2 ),
266 $settings['quantity_measurement_plural']
267 );
268 ?>
269
270 <div class="tiered-pricing-option"
271 data-tiered-quantity="<?php
272 echo esc_attr( $currentQuantity );
273 ?>"
274 data-tiered-price="<?php
275 echo esc_attr( $currentProductPrice );
276 ?>"
277 data-tiered-price-exclude-taxes="<?php
278 echo esc_attr( $currentProductPriceExcludeTaxes );
279 ?>"
280 data-tiered-price-include-taxes="<?php
281 echo esc_attr( $currentProductPriceIncludeTaxes );
282 ?>">
283 <div class="tiered-pricing-option__checkbox">
284 <div class="tiered-pricing-option-checkbox"></div>
285 </div>
286 <div class="tiered-pricing-option__quantity">
287 <?php
288 echo wp_kses_post( $optionText );
289 ?>
290 <?php
291 do_action(
292 'tiered_pricing_table/options/label',
293 $pricing_rule,
294 $currentQuantity,
295 array(
296 'id' => $id,
297 'style' => '6',
298 )
299 );
300 ?>
301 </div>
302 <div class="tiered-pricing-option__pricing">
303 <div class="tiered-pricing-option-price">
304 <?php
305 if ( $discountAmount > 0 ) {
306 ?>
307 <div class="tiered-pricing-option-price__original"><del><?php
308 echo wp_kses_post( wc_price( wc_get_price_to_display( $product, array(
309 'price' => ( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $regular_price : $real_price ),
310 ) ) ) );
311 ?></del></div>
312 <?php
313 }
314 ?>
315 <div class="tiered-pricing-option-price__discounted"><?php
316 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity, $product_id ) ) );
317 ?></div>
318 <?php
319 if ( $settings['show_discount_column'] && $discountAmount > 0 ) {
320 ?>
321 <span class="tiered-pricing-option__discount-label">(<?php
322 echo wp_kses_post( PricingTable::formatDiscount(
323 $discountAmount,
324 $pricing_rule,
325 $product,
326 $currentQuantity,
327 $settings,
328 'off'
329 ) );
330 ?>)</span>
331 <?php
332 }
333 ?>
334 </div>
335 <?php
336 ?>
337 </div>
338 </div>
339 <?php
340 $tptTierRows[] = ob_get_clean();
341 }
342 ?>
343 <?php
344 echo PricingTable::orderTiers( $tptTierRows, $settings );
345 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above
346 ?>
347
348 <?php
349 do_action( 'tiered_pricing_table/options/options', $pricing_rule, $settings );
350 ?>
351 </div>
352
353 <?php
354 do_action( 'tiered_pricing_table/options/after_options', $pricing_rule );
355 ?>
356 </div>
357
358 <style>
359 <?php
360 if ( !$settings['options_show_default_option'] ) {
361 echo esc_html( "#{$id} .tiered-pricing-option--default { display: none }" );
362 }
363 if ( !$settings['options_show_original_product_price'] ) {
364 echo esc_html( "#{$id} .tiered-pricing-option-price__original { display: none }" );
365 echo esc_html( "#{$id} .tiered-pricing-option-total__original_total { display: none }" );
366 }
367 $tint = Settings::hex2rgba( $settings['active_tier_color'], 0.08 );
368 $color = $settings['active_tier_color'];
369 echo esc_html( "#{$id} .tiered-pricing--active { background: {$tint}; }" );
370 echo esc_html( "#{$id} .tiered-pricing--active .tiered-pricing-option-checkbox { background: {$color}; border-color: {$color}; }" );
371 echo esc_html( "#{$id} .tiered-pricing--active .tiered-pricing-option__discount-label { color: {$color}; }" );
372 ?>
373 </style>
374 <?php
375 }