| @@ -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 | } |
| @@ -65,8 +66,13 @@ | ||
| 65 | 66 | |
| 66 | 67 | <div class="tiered-pricing-options <?php |
| 67 | 68 | echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ? 'tiered-pricing-options--slim' : '' ); |
| 68 | 69 | ?>" |
| 70 | + | |
| 71 | + <?php | |
| 72 | + echo PricingTable::layoutStyleAttribute( $settings ); | |
| 73 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper | |
| 74 | + ?> | |
| 69 | 75 | id="<?php |
| 70 | 76 | echo esc_attr( $id ); |
| 71 | 77 | ?>" |
| 72 | 78 | data-product-id="<?php |
| @@ -72,9 +78,9 @@ | ||
| 72 | 78 | data-product-id="<?php |
| 73 | 79 | echo esc_attr( $product_id ); |
| 74 | 80 | ?>" |
| 75 | 81 | data-price-rules="<?php |
| 76 | - echo esc_attr( htmlspecialchars( json_encode( $price_rules ) ) ); | |
| 82 | + echo esc_attr( htmlspecialchars( json_encode( $price_rules ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) ); | |
| 77 | 83 | ?>" |
| 78 | 84 | data-minimum="<?php |
| 79 | 85 | echo esc_attr( $minimum ); |
| 80 | 86 | ?>" |
| @@ -93,8 +99,12 @@ | ||
| 93 | 99 | data-product-price-suffix="<?php |
| 94 | 100 | echo esc_attr( $product->get_price_suffix() ); |
| 95 | 101 | ?>" |
| 96 | 102 | > |
| 103 | + <?php | |
| 104 | + $tptTierRows = array(); | |
| 105 | + ob_start(); | |
| 106 | + ?> | |
| 97 | 107 | <div class="tiered-pricing-option tiered-pricing--active tiered-pricing-option--default" |
| 98 | 108 | data-tiered-quantity="<?php |
| 99 | 109 | echo esc_attr( $minimum ); |
| 100 | 110 | ?>" |
| @@ -132,9 +142,9 @@ | ||
| 132 | 142 | if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) { |
| 133 | 143 | ?> |
| 134 | 144 | <?php |
| 135 | 145 | $quantity = esc_attr( number_format_i18n( $minimum ) . ' ' ); |
| 136 | - $baseUnitName = $settings['quantity_measurement_singular']; | |
| 146 | + $baseUnitName = ( $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] ); | |
| 137 | 147 | ?> |
| 138 | 148 | <?php |
| 139 | 149 | } else { |
| 140 | 150 | ?> |
| @@ -152,9 +162,9 @@ | ||
| 152 | 162 | <?php |
| 153 | 163 | echo wp_kses_post( tptParseOptionText( |
| 154 | 164 | $settings['options_option_text'], |
| 155 | 165 | $quantity, |
| 156 | - $discountAmount, | |
| 166 | + round( $discountAmount, 2 ), | |
| 157 | 167 | $baseUnitName |
| 158 | 168 | ) ); |
| 159 | 169 | ?> |
| 160 | 170 | <?php |
| @@ -216,8 +226,11 @@ | ||
| 216 | 226 | <?php |
| 217 | 227 | ?> |
| 218 | 228 | </div> |
| 219 | 229 | </div> |
| 230 | + <?php | |
| 231 | + $tptTierRows[] = ob_get_clean(); | |
| 232 | + ?> | |
| 220 | 233 | |
| 221 | 234 | <?php |
| 222 | 235 | $iterator = new ArrayIterator($price_rules); |
| 223 | 236 | ?> |
| @@ -223,8 +236,9 @@ | ||
| 223 | 236 | ?> |
| 224 | 237 | |
| 225 | 238 | <?php |
| 226 | 239 | while ( $iterator->valid() ) { |
| 240 | + ob_start(); | |
| 227 | 241 | ?> |
| 228 | 242 | <?php |
| 229 | 243 | $currentPrice = $iterator->current(); |
| 230 | 244 | $currentQuantity = $iterator->key(); |
| @@ -234,14 +248,11 @@ | ||
| 234 | 248 | $discountAmount = PriceManager::calculateDiscount( ( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price() ), $pricing_rule->getTierPrice( $currentQuantity, false ) ); |
| 235 | 249 | } |
| 236 | 250 | $iterator->next(); |
| 237 | 251 | if ( $iterator->valid() ) { |
| 238 | - $quantity = $currentQuantity; | |
| 239 | - if ( intval( $iterator->key() - 1 != $currentQuantity ) ) { | |
| 240 | - $quantity = number_format_i18n( $quantity ); | |
| 241 | - if ( 'range' === $settings['quantity_type'] ) { | |
| 242 | - $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) ); | |
| 243 | - } | |
| 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 ) ); | |
| 244 | 255 | } |
| 245 | 256 | } else { |
| 246 | 257 | $quantity = number_format_i18n( $currentQuantity ); |
| 247 | 258 | $quantity .= apply_filters( |
| @@ -335,9 +346,14 @@ | ||
| 335 | 346 | ?> |
| 336 | 347 | </div> |
| 337 | 348 | </div> |
| 338 | 349 | <?php |
| 350 | + $tptTierRows[] = ob_get_clean(); | |
| 339 | 351 | } |
| 352 | + ?> | |
| 353 | + <?php | |
| 354 | + echo PricingTable::orderTiers( $tptTierRows, $settings ); | |
| 355 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above | |
| 340 | 356 | ?> |
| 341 | 357 | |
| 342 | 358 | <?php |
| 343 | 359 | do_action( 'tiered_pricing_table/options/options', $pricing_rule, $settings ); |