| @@ -15,8 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | use TierPricingTable\CalculationLogic; |
| 18 | 18 | use TierPricingTable\PriceManager; |
| 19 | + use TierPricingTable\PricingTable; | |
| 19 | 20 | use TierPricingTable\PricingRule; |
| 20 | 21 | |
| 21 | 22 | if ( ! defined( 'WPINC' ) ) { |
| 22 | 23 | die; |
| @@ -70,8 +71,9 @@ | ||
| 70 | 71 | <?php do_action( 'tiered_pricing_table/tiered_pricing/before', $pricing_rule ); ?> |
| 71 | 72 | |
| 72 | 73 | <div class="tiered-pricing-horizontal-table <?php echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ) ? 'tiered-pricing-horizontal-table--slim' : ''; ?>" |
| 73 | 74 | id="<?php echo esc_attr( $id ); ?>" |
| 75 | + <?php echo \TierPricingTable\PricingTable::layoutStyleAttribute( $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper ?> | |
| 74 | 76 | data-tiered-pricing-table |
| 75 | 77 | data-product-id="<?php echo esc_attr( $product_id ); ?>" |
| 76 | 78 | data-price-rules=" |
| 77 | 79 | <?php |
| @@ -110,10 +112,11 @@ | ||
| 110 | 112 | </strong> |
| 111 | 113 | </div> |
| 112 | 114 | <?php endif; ?> |
| 113 | 115 | |
| 114 | - <?php echo str_replace(['<th', '</th>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_head); ?> | |
| 116 | + <?php echo wp_kses_post( str_replace(['<th', '</th>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_head) ); ?> | |
| 115 | 117 | </div> |
| 118 | + <?php $tptTierRows = array(); ob_start(); ?> | |
| 116 | 119 | <div class="tiered-pricing-horizontal-table-column tiered-pricing-horizontal-table__values tiered-pricing--active" |
| 117 | 120 | data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>" |
| 118 | 121 | data-tiered-price="<?php echo esc_attr( $price ); ?>" |
| 119 | 122 | data-tiered-price-exclude-taxes="<?php echo esc_attr( $price_excl_taxes ); ?>" |
| @@ -126,9 +129,9 @@ | ||
| 126 | 129 | <span> |
| 127 | 130 | <?php echo esc_attr( number_format_i18n( $minimum ) ); ?> |
| 128 | 131 | </span> |
| 129 | 132 | <span> |
| 130 | - <?php echo esc_attr( ' ' . $settings['quantity_measurement_singular'] ); ?> | |
| 133 | + <?php echo esc_attr( ' ' . ( $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] ) ); ?> | |
| 131 | 134 | </span> |
| 132 | 135 | </span> |
| 133 | 136 | <?php else : ?> |
| 134 | 137 | <span> |
| @@ -162,9 +165,9 @@ | ||
| 162 | 165 | ?> |
| 163 | 166 | |
| 164 | 167 | <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--discount"> |
| 165 | 168 | <?php if ( $discountAmount > 0 ) : ?> |
| 166 | - <span><?php echo esc_attr( round( $discountAmount, 2 ) ); ?> %</span> | |
| 169 | + <span><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings ) ); ?></span> | |
| 167 | 170 | <?php else : ?> |
| 168 | 171 | <span>—</span> |
| 169 | 172 | <?php endif; ?> |
| 170 | 173 | </div> |
| @@ -182,15 +185,16 @@ | ||
| 182 | 185 | <?php |
| 183 | 186 | ob_start(); |
| 184 | 187 | do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, null ); |
| 185 | 188 | $custom_cols = ob_get_clean(); |
| 186 | - echo str_replace(['<td', '</td>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_cols); | |
| 189 | + echo wp_kses_post( str_replace(['<td', '</td>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_cols) ); | |
| 187 | 190 | ?> |
| 188 | 191 | </div> |
| 192 | + <?php $tptTierRows[] = ob_get_clean(); ?> | |
| 189 | 193 | |
| 190 | 194 | <?php $iterator = new ArrayIterator( $pricing_rule->getRules() ); ?> |
| 191 | 195 | |
| 192 | - <?php while ( $iterator->valid() ) : ?> | |
| 196 | + <?php while ( $iterator->valid() ) : ob_start(); ?> | |
| 193 | 197 | <?php |
| 194 | 198 | $currentPrice = $iterator->current(); |
| 195 | 199 | $currentQuantity = $iterator->key(); |
| 196 | 200 | |
| @@ -252,9 +256,9 @@ | ||
| 252 | 256 | <?php if ( $settings['discount_column_title'] ) : ?> |
| 253 | 257 | <div |
| 254 | 258 | class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--discount"> |
| 255 | 259 | <?php if ( $discountAmount > 0 ) : ?> |
| 256 | - <span><?php echo esc_attr( round( $discountAmount, 2 ) ); ?> %</span> | |
| 260 | + <span><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings ) ); ?></span> | |
| 257 | 261 | <?php else : ?> |
| 258 | 262 | <span>—</span> |
| 259 | 263 | <?php endif; ?> |
| 260 | 264 | </div> |
| @@ -271,12 +275,15 @@ | ||
| 271 | 275 | <?php |
| 272 | 276 | ob_start(); |
| 273 | 277 | do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, $currentQuantity ); |
| 274 | 278 | $custom_cols = ob_get_clean(); |
| 275 | - echo str_replace(['<td', '</td>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_cols); | |
| 279 | + echo wp_kses_post( str_replace(['<td', '</td>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_cols) ); | |
| 276 | 280 | ?> |
| 277 | 281 | </div> |
| 278 | - <?php endwhile; ?> | |
| 282 | + <?php $tptTierRows[] = ob_get_clean(); endwhile; ?> | |
| 283 | + <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?> | |
| 284 | + | |
| 285 | + <?php do_action( 'tiered_pricing_table/horizontal-table/after_columns', $pricing_rule, $settings ); ?> | |
| 279 | 286 | </div> |
| 280 | 287 | |
| 281 | 288 | <?php do_action( 'tiered_pricing_table/tiered_pricing/after', $pricing_rule ); ?> |
| 282 | 289 | </div> |