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-3.php

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

436 lines 13.2 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 if ( !empty( $price_rules ) ) {
54 ?>
55
56 <div class="tiered-pricing-wrapper">
57 <?php
58 if ( !empty( $settings['title'] ) ) {
59 ?>
60 <h3 style="clear:both; margin: 20px 0;"><?php
61 echo esc_attr( $settings['title'] );
62 ?></h3>
63 <?php
64 }
65 ?>
66
67 <div class="tiered-pricing-options tiered-pricing-options--styled tiered-pricing-options--style-3 <?php
68 echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ? 'tiered-pricing-options--slim' : '' );
69 ?>"
70
71 <?php
72 echo PricingTable::layoutStyleAttribute( $settings );
73 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper
74 ?>
75 id="<?php
76 echo esc_attr( $id );
77 ?>"
78 data-product-id="<?php
79 echo esc_attr( $product_id );
80 ?>"
81 data-price-rules="<?php
82 echo esc_attr( htmlspecialchars( json_encode( $price_rules ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) );
83 ?>"
84 data-minimum="<?php
85 echo esc_attr( $minimum );
86 ?>"
87 data-product-name="<?php
88 echo esc_attr( $product_name );
89 ?>"
90 data-regular-price="<?php
91 echo esc_attr( $regular_price );
92 ?>"
93 data-sale-price="<?php
94 echo esc_attr( $sale_price );
95 ?>"
96 data-price="<?php
97 echo esc_attr( $price );
98 ?>"
99 data-product-price-suffix="<?php
100 echo esc_attr( $product->get_price_suffix() );
101 ?>"
102 >
103 <?php
104 $tptTierRows = array();
105 ob_start();
106 ?>
107 <div class="tiered-pricing-option tiered-pricing--active tiered-pricing-option--default"
108 data-tiered-quantity="<?php
109 echo esc_attr( $minimum );
110 ?>"
111 data-tiered-price="<?php
112 echo esc_attr( $price );
113 ?>"
114 data-tiered-price-exclude-taxes="
115 <?php
116 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
117 'price' => $real_price,
118 ) ) );
119 ?>
120 "
121 data-tiered-price-include-taxes="
122 <?php
123 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
124 'price' => $real_price,
125 ) ) );
126 ?>
127 "
128 >
129 <div class="tiered-pricing-option-inner">
130 <div class="tiered-pricing-option__checkbox">
131 <div class="tiered-pricing-option-checkbox tiered-pricing-option-checkbox--active"></div>
132 </div>
133
134 <?php
135 $discountAmount = 0;
136 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
137 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(), $product->get_sale_price() );
138 }
139 ?>
140
141 <div class="tiered-pricing-option__quantity">
142 <?php
143 if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) {
144 ?>
145 <?php
146 $quantity = esc_attr( number_format_i18n( $minimum ) . ' ' );
147 $baseUnitName = ( $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] );
148 ?>
149 <?php
150 } else {
151 ?>
152 <?php
153 $quantity = esc_attr( number_format_i18n( $minimum ) . ' - ' . number_format_i18n( array_keys( $price_rules )[0] - 1 ) . ' ' );
154 $baseUnitName = $settings['quantity_measurement_plural'];
155 ?>
156 <?php
157 }
158 ?>
159
160 <?php
161 if ( $discountAmount > 0 ) {
162 ?>
163 <?php
164 echo wp_kses_post( tptParseOptionText(
165 $settings['options_option_text'],
166 $quantity,
167 round( $discountAmount, 2 ),
168 $baseUnitName
169 ) );
170 ?>
171 <?php
172 } else {
173 ?>
174 <?php
175 echo wp_kses_post( tptParseOptionText(
176 $settings['options_default_option_text'],
177 $quantity,
178 null,
179 $baseUnitName
180 ) );
181 ?>
182 <?php
183 }
184 ?>
185 </div>
186
187 <?php
188 do_action(
189 'tiered_pricing_table/options/label',
190 $pricing_rule,
191 $minimum,
192 array(
193 'id' => $id,
194 'style' => '3',
195 )
196 );
197 ?>
198
199 <div class="tiered-pricing-option__pricing">
200 <div class="tiered-pricing-option-price">
201
202 <?php
203 if ( $discountAmount > 0 ) {
204 ?>
205 <div class="tiered-pricing-option-price__original">
206 <del>
207 <?php
208 echo wp_kses_post( wc_price( $regular_price ) );
209 ?>
210 </del>
211 </div>
212 <?php
213 }
214 ?>
215
216 <div class="tiered-pricing-option-price__discounted">
217 <?php
218 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
219 'price' => $real_price,
220 ) ) ) );
221 ?>
222 </div>
223
224 </div>
225
226 <?php
227 ?>
228
229 <?php
230 if ( $settings['show_discount_column'] && $discountAmount > 0 ) {
231 ?>
232 <div class="tiered-pricing-option__discount-label">
233 <?php
234 echo wp_kses_post( PricingTable::formatDiscount(
235 $discountAmount,
236 $pricing_rule,
237 $product,
238 null,
239 $settings,
240 'off'
241 ) );
242 ?>
243 </div>
244 <?php
245 }
246 ?>
247
248 </div>
249 </div>
250 </div>
251 <?php
252 $tptTierRows[] = ob_get_clean();
253 ?>
254
255 <?php
256 $iterator = new ArrayIterator($price_rules);
257 ?>
258
259 <?php
260 while ( $iterator->valid() ) {
261 ob_start();
262 ?>
263 <?php
264 $currentPrice = $iterator->current();
265 $currentQuantity = $iterator->key();
266 if ( 'percentage' === $pricing_type ) {
267 $discountAmount = $currentPrice;
268 } else {
269 $discountAmount = PriceManager::calculateDiscount( ( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price() ), $pricing_rule->getTierPrice( $currentQuantity, false ) );
270 }
271 $iterator->next();
272 if ( $iterator->valid() ) {
273 $quantity = number_format_i18n( $currentQuantity );
274 if ( (int) $iterator->key() - 1 !== (int) $currentQuantity && 'range' === $settings['quantity_type'] ) {
275 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
276 }
277 } else {
278 $quantity = number_format_i18n( $currentQuantity );
279 $quantity .= apply_filters(
280 'tiered_pricing_table/tiered_pricing/last_tier_postfix',
281 '+',
282 $currentQuantity,
283 $pricing_rule,
284 'blocks'
285 );
286 }
287 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
288 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
289 'price' => PriceManager::getPriceByRules(
290 $currentQuantity,
291 $product_id,
292 null,
293 null,
294 false
295 ),
296 ) );
297 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
298 'price' => PriceManager::getPriceByRules(
299 $currentQuantity,
300 $product_id,
301 null,
302 null,
303 false
304 ),
305 ) );
306 ?>
307
308 <div class="tiered-pricing-option"
309 data-tiered-quantity="<?php
310 echo esc_attr( $currentQuantity );
311 ?>"
312 data-tiered-price="<?php
313 echo esc_attr( $currentProductPrice );
314 ?>"
315 data-tiered-price-exclude-taxes="<?php
316 echo esc_attr( $currentProductPriceExcludeTaxes );
317 ?>"
318 data-tiered-price-include-taxes="<?php
319 echo esc_attr( $currentProductPriceIncludeTaxes );
320 ?>">
321
322 <?php
323 if ( $settings['show_discount_column'] && $discountAmount > 0 ) {
324 ?>
325 <div class="tiered-pricing-option__discount-label">
326 <?php
327 echo wp_kses_post( PricingTable::formatDiscount(
328 $discountAmount,
329 $pricing_rule,
330 $product,
331 $currentQuantity,
332 $settings,
333 'off'
334 ) );
335 ?>
336 </div>
337 <?php
338 }
339 ?>
340
341 <div class="tiered-pricing-option-inner">
342 <div class="tiered-pricing-option__checkbox">
343 <div class="tiered-pricing-option-checkbox"></div>
344 </div>
345 <div class="tiered-pricing-option__quantity">
346 <?php
347 echo wp_kses_post( tptParseOptionText(
348 $settings['options_option_text'],
349 $quantity,
350 round( $discountAmount, 2 ),
351 $settings['quantity_measurement_plural']
352 ) );
353 ?>
354 </div>
355
356 <?php
357 do_action(
358 'tiered_pricing_table/options/label',
359 $pricing_rule,
360 $currentQuantity,
361 array(
362 'id' => $id,
363 'style' => '3',
364 )
365 );
366 ?>
367
368 <div class="tiered-pricing-option__pricing">
369 <div class="tiered-pricing-option-price">
370 <div class="tiered-pricing-option-price__original">
371 <del>
372 <?php
373 echo wp_kses_post( wc_price( wc_get_price_to_display( $product, array(
374 'price' => ( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $regular_price : $real_price ),
375 ) ) ) );
376 ?>
377 </del>
378 </div>
379 <div class="tiered-pricing-option-price__discounted">
380 <?php
381 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity, $product_id ) ) );
382 ?>
383 </div>
384 </div>
385
386 <?php
387 ?>
388 </div>
389 </div>
390
391
392 </div>
393 <?php
394 $tptTierRows[] = ob_get_clean();
395 }
396 ?>
397 <?php
398 echo PricingTable::orderTiers( $tptTierRows, $settings );
399 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above
400 ?>
401
402 <?php
403 do_action( 'tiered_pricing_table/options/options', $pricing_rule, $settings );
404 ?>
405 </div>
406
407 <?php
408 do_action( 'tiered_pricing_table/options/after_options', $pricing_rule );
409 ?>
410 </div>
411
412 <style>
413 <?php
414 if ( !$settings['options_show_default_option'] ) {
415 echo esc_html( "#{$id} .tiered-pricing-option--default { display: none }" );
416 }
417 $background_05percent = Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.05 );
418 $background_20percent = Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.3 );
419 $background_50percent = Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.5 );
420 $background_80percent = Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.8 );
421 echo esc_html( "#{$id} .tiered-pricing--active .tiered-pricing-option-checkbox::after {\n\t\t\tbackground: {$settings['active_tier_color']};\n\t\t}" );
422 echo esc_html( "#{$id} .tiered-pricing--active .tiered-pricing-option-checkbox {\n\t\t\tborder-color: {$settings['active_tier_color']};\n\t\t}" );
423 echo esc_html( "#{$id} .tiered-pricing-option__discount-label {\n\t\t\tbackground: {$background_80percent};\n\t\t}" );
424 echo esc_html( "#{$id} .tiered-pricing--active {\n\t\t\tbackground: {$background_05percent};\n\t\t}" );
425 echo esc_html( "#{$id} .tiered-pricing-option {\n\t\t\tborder-color: {$background_20percent};\n\t\t}" );
426 echo esc_html( "#{$id} .tiered-pricing--active {\n\t\t\tbackground: {$background_05percent};\n\t\t\tborder-color: {$background_80percent};\n\t\t}" );
427 echo esc_html( "#{$id} .tiered-pricing--active .tiered-pricing-option__discount-label {\n\t\t\tbackground: {$settings['active_tier_color']};\n\t\t}" );
428 echo esc_html( "#{$id} {\n\t\t\tborder-color: {$background_20percent};\n\t\t}" );
429 if ( !$settings['options_show_original_product_price'] ) {
430 echo esc_html( "#{$id} .tiered-pricing-option-price__original {\n\t\t\t\tdisplay: none\n\t\t\t}" );
431 echo esc_html( "#{$id} .tiered-pricing-option-total__original_total {\n\t\t\t\tdisplay: none\n\t\t\t}" );
432 }
433 ?>
434 </style>
435 <?php
436 }