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-plain-text.php +15 -16 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
7 8 if ( ! defined( 'WPINC' ) ) {
8 9 die;
@@ -41,9 +42,9 @@
41 42 if ( ! function_exists( 'tptParsePlainText' ) ) {
42 43 function tptParsePlainText( $text, $quantity, $discount = null, $price = null, $base_unit_name = null ) {
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_price}' => $price ? wc_price( $price ) : '',
48 49 '{tp_base_unit_name}' => $base_unit_name,
49 50 ) );
@@ -59,9 +60,9 @@
59 60
60 61 <ul class="tiered-pricing-plain-texts"
61 62 id="<?php echo esc_attr( $id ); ?>"
62 63 data-product-id="<?php echo esc_attr( $product_id ); ?>"
63 - data-price-rules="<?php echo esc_attr( htmlspecialchars( json_encode( $price_rules ) ) ); ?>"
64 + data-price-rules="<?php echo esc_attr( htmlspecialchars( json_encode( $price_rules ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) ); ?>"
64 65 data-minimum="<?php echo esc_attr( $minimum ); ?>"
65 66 data-product-name="<?php echo esc_attr( $product_name ); ?>"
66 67 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
67 68 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
@@ -67,8 +68,9 @@
67 68 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
68 69 data-price="<?php echo esc_attr( $price ); ?>"
69 70 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
70 71 >
72 + <?php $tptTierRows = array(); ob_start(); ?>
71 73 <li class="tiered-pricing-plain-text tiered-pricing--active tiered-pricing-plain-text--default"
72 74 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
73 75 data-tiered-price="<?php echo esc_attr( $price ); ?>"
74 76 data-tiered-price-exclude-taxes="
@@ -96,9 +98,9 @@
96 98
97 99 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
98 100 <?php
99 101 $quantity = esc_attr( number_format_i18n( $minimum ) . ' ' );
100 - $baseUnitName = $settings['quantity_measurement_singular'];
102 + $baseUnitName = $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'];
101 103 ?>
102 104 <?php else : ?>
103 105 <?php
104 106 $quantity = esc_attr( number_format_i18n( $minimum ) . ' - ' . number_format_i18n( array_keys( $price_rules )[0] - 1 ) . ' ' );
@@ -108,9 +110,9 @@
108 110
109 111 <?php if ( $discountAmount > 0 ) : ?>
110 112 <?php
111 113 echo wp_kses_post( tptParsePlainText( $settings['plain_text_option_text'], $quantity,
112 - $discountAmount, $price, $baseUnitName ) );
114 + round( $discountAmount, 2 ), $price, $baseUnitName ) );
113 115 ?>
114 116 <?php else : ?>
115 117 <?php
116 118 echo wp_kses_post( tptParsePlainText( $settings['plain_text_default_option_text'], $quantity, null,
@@ -124,12 +126,13 @@
124 126 'style' => 'default',
125 127 ) );
126 128 ?>
127 129 </li>
130 + <?php $tptTierRows[] = ob_get_clean(); ?>
128 131
129 132 <?php $iterator = new ArrayIterator( $price_rules ); ?>
130 133
131 - <?php while ( $iterator->valid() ) : ?>
134 + <?php while ( $iterator->valid() ) : ob_start(); ?>
132 135 <?php
133 136 $currentPrice = $iterator->current();
134 137 $currentQuantity = $iterator->key();
135 138
@@ -142,17 +145,12 @@
142 145
143 146 $iterator->next();
144 147
145 148 if ( $iterator->valid() ) {
146 - $quantity = $currentQuantity;
149 + $quantity = number_format_i18n( $currentQuantity );
147 150
148 - if ( intval( $iterator->key() - 1 != $currentQuantity ) ) {
149 -
150 - $quantity = number_format_i18n( $quantity );
151 -
152 - if ( 'range' === $settings['quantity_type'] ) {
153 - $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
154 - }
151 + if ( (int) $iterator->key() - 1 !== (int) $currentQuantity && 'range' === $settings['quantity_type'] ) {
152 + $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
155 153 }
156 154 } else {
157 155 $quantity = number_format_i18n( $currentQuantity );
158 156
@@ -191,14 +189,15 @@
191 189 'style' => 'default',
192 190 ) );
193 191 ?>
194 192 </li>
195 - <?php endwhile; ?>
193 + <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
194 + <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
196 195
197 - <?php do_action( 'tiered_pricing_table/options/options', $pricing_rule ); ?>
196 + <?php do_action( 'tiered_pricing_table/plain-text/line', $pricing_rule, $settings ); ?>
198 197 </ul>
199 198
200 - <?php do_action( 'tiered_pricing_table/options/after_options', $pricing_rule ); ?>
199 + <?php do_action( 'tiered_pricing_table/plain-text/after_lines', $pricing_rule, $settings ); ?>
201 200 </div>
202 201
203 202 <style>
204 203 <?php