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
← All changes | views/frontend/tiered-pricing-options.php +30 -12 6.1.0 → 8.1.0 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 use TierPricingTable\CalculationLogic;
4 4 use TierPricingTable\PriceManager;
5 +use TierPricingTable\PricingTable;
5 6 use TierPricingTable\PricingRule;
6 7 use TierPricingTable\Settings\Settings;
7 8 if ( !defined( 'WPINC' ) ) {
8 9 die;
@@ -41,9 +42,9 @@
41 42 $base_unit_name = null
42 43 ) {
43 44 return strtr( $text, array(
44 45 '{tp_quantity}' => $quantity,
45 - '{tp_discount}' => $discount,
46 + '{tp_discount}' => ( !is_null( $discount ) ? round( (float) $discount, \TierPricingTable\PricingTable::discountDecimals( (float) $discount ) ) : $discount ),
46 47 '{tp_rounded_discount}' => ( !is_null( $discount ) ? round( $discount ) : 0 ),
47 48 '{tp_base_unit_name}' => $base_unit_name,
48 49 ) );
49 50 }
@@ -62,9 +63,16 @@
62 63 <?php
63 64 }
64 65 ?>
65 66
66 - <div class="tiered-pricing-options"
67 + <div class="tiered-pricing-options <?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 + ?>
67 75 id="<?php
68 76 echo esc_attr( $id );
69 77 ?>"
70 78 data-product-id="<?php
@@ -70,9 +78,9 @@
70 78 data-product-id="<?php
71 79 echo esc_attr( $product_id );
72 80 ?>"
73 81 data-price-rules="<?php
74 - echo esc_attr( htmlspecialchars( json_encode( $price_rules ) ) );
82 + echo esc_attr( htmlspecialchars( json_encode( $price_rules ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) );
75 83 ?>"
76 84 data-minimum="<?php
77 85 echo esc_attr( $minimum );
78 86 ?>"
@@ -91,8 +99,12 @@
91 99 data-product-price-suffix="<?php
92 100 echo esc_attr( $product->get_price_suffix() );
93 101 ?>"
94 102 >
103 + <?php
104 + $tptTierRows = array();
105 + ob_start();
106 + ?>
95 107 <div class="tiered-pricing-option tiered-pricing--active tiered-pricing-option--default"
96 108 data-tiered-quantity="<?php
97 109 echo esc_attr( $minimum );
98 110 ?>"
@@ -130,9 +142,9 @@
130 142 if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) {
131 143 ?>
132 144 <?php
133 145 $quantity = esc_attr( number_format_i18n( $minimum ) . ' ' );
134 - $baseUnitName = $settings['quantity_measurement_singular'];
146 + $baseUnitName = ( $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] );
135 147 ?>
136 148 <?php
137 149 } else {
138 150 ?>
@@ -150,9 +162,9 @@
150 162 <?php
151 163 echo wp_kses_post( tptParseOptionText(
152 164 $settings['options_option_text'],
153 165 $quantity,
154 - $discountAmount,
166 + round( $discountAmount, 2 ),
155 167 $baseUnitName
156 168 ) );
157 169 ?>
158 170 <?php
@@ -214,8 +226,11 @@
214 226 <?php
215 227 ?>
216 228 </div>
217 229 </div>
230 + <?php
231 + $tptTierRows[] = ob_get_clean();
232 + ?>
218 233
219 234 <?php
220 235 $iterator = new ArrayIterator($price_rules);
221 236 ?>
@@ -221,8 +236,9 @@
221 236 ?>
222 237
223 238 <?php
224 239 while ( $iterator->valid() ) {
240 + ob_start();
225 241 ?>
226 242 <?php
227 243 $currentPrice = $iterator->current();
228 244 $currentQuantity = $iterator->key();
@@ -232,14 +248,11 @@
232 248 $discountAmount = PriceManager::calculateDiscount( ( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price() ), $pricing_rule->getTierPrice( $currentQuantity, false ) );
233 249 }
234 250 $iterator->next();
235 251 if ( $iterator->valid() ) {
236 - $quantity = $currentQuantity;
237 - if ( intval( $iterator->key() - 1 != $currentQuantity ) ) {
238 - $quantity = number_format_i18n( $quantity );
239 - if ( 'range' === $settings['quantity_type'] ) {
240 - $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
241 - }
252 + $quantity = number_format_i18n( $currentQuantity );
253 + if ( (int) $iterator->key() - 1 !== (int) $currentQuantity && 'range' === $settings['quantity_type'] ) {
254 + $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
242 255 }
243 256 } else {
244 257 $quantity = number_format_i18n( $currentQuantity );
245 258 $quantity .= apply_filters(
@@ -333,13 +346,18 @@
333 346 ?>
334 347 </div>
335 348 </div>
336 349 <?php
350 + $tptTierRows[] = ob_get_clean();
337 351 }
338 352 ?>
353 + <?php
354 + echo PricingTable::orderTiers( $tptTierRows, $settings );
355 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above
356 + ?>
339 357
340 358 <?php
341 - do_action( 'tiered_pricing_table/options/options', $pricing_rule );
359 + do_action( 'tiered_pricing_table/options/options', $pricing_rule, $settings );
342 360 ?>
343 361 </div>
344 362
345 363 <?php