PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
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 2.3.3 All 91 releases
tier-pricing-table / views / frontend / tiered-pricing-blocks-style-3.php

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

280 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php use TierPricingTable\CalculationLogic;
2 use TierPricingTable\PriceManager;
3 use TierPricingTable\PricingTable;
4 use TierPricingTable\PricingRule;
5 use TierPricingTable\Settings\Settings;
6
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10 /**
11 * Available variables
12 *
13 * @var array $price_rules
14 * @var PricingRule $pricing_rule
15 * @var string $real_price
16 * @var string $product_name
17 * @var string $pricing_type
18 * @var WC_Product $product
19 * @var string $id
20 * @var int $product_id
21 * @var int $minimum
22 * @var array $settings
23 */
24
25 $sale_price = $product->get_sale_price();
26
27 if ( $sale_price ) {
28 $sale_price = wc_get_price_to_display( $product, array(
29 'price' => $sale_price,
30 ) );
31 }
32
33 $regular_price = wc_get_price_to_display( $product, array(
34 'price' => $product->get_regular_price(),
35 ) );
36
37 $price = wc_get_price_to_display( $product, array(
38 'price' => $product->get_price(),
39 ) );
40
41 ?>
42
43 <?php if ( ! empty( $price_rules ) ) : ?>
44
45 <div class="tiered-pricing-wrapper">
46 <?php if ( ! empty( $settings['title'] ) ) : ?>
47 <h3 style="clear:both; margin: 20px 0;"><?php echo esc_attr( $settings['title'] ); ?></h3>
48 <?php endif; ?>
49
50 <div class="tiered-pricing-blocks tiered-pricing-blocks--styled tiered-pricing-blocks--style-3 <?php echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ) ? 'tiered-pricing-blocks--slim' : ''; ?>"
51
52 <?php echo PricingTable::layoutStyleAttribute( $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper ?>
53 id="<?php echo esc_attr( $id ); ?>"
54 data-product-id="<?php echo esc_attr( $product_id ); ?>"
55 data-price-rules="<?php echo esc_attr( htmlspecialchars( json_encode( $price_rules ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) ); ?>"
56 data-minimum="<?php echo esc_attr( $minimum ); ?>"
57 data-product-name="<?php echo esc_attr( $product_name ); ?>"
58 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
59 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
60 data-price="<?php echo esc_attr( $price ); ?>"
61 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
62 >
63
64 <?php $tptTierRows = array(); ob_start(); ?>
65 <div class="tiered-pricing-block tiered-pricing--active"
66 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
67 data-tiered-price="
68 <?php
69 echo esc_attr( wc_get_price_to_display( wc_get_product( $product_id ), array(
70 'price' => $real_price,
71 ) ) );
72 ?>
73 "
74 data-tiered-price-exclude-taxes="
75 <?php
76 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
77 'price' => $real_price,
78 ) ) );
79 ?>
80 "
81 data-tiered-price-include-taxes="
82 <?php
83 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
84 'price' => $real_price,
85 ) ) );
86 ?>
87 ">
88
89 <?php if ( $settings['show_discount_column'] ) : ?>
90 <?php
91 $discountAmount = 0;
92 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
93 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
94 $product->get_sale_price() );
95 }
96 ?>
97 <?php if ( $discountAmount > 0 ) : ?>
98 <div class="tiered-pricing-block__discount">
99 <span class="tiered-pricing-block__price-discount">
100 <?php
101 echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings, 'off' ) );
102 ?>
103 </span>
104 </div>
105 <?php endif; ?>
106 <?php endif; ?>
107 <div class="tiered-pricing-block-inner">
108
109 <?php
110 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $minimum, array(
111 'id' => $id,
112 'style' => '3',
113 ) );
114 ?>
115
116 <div class="tiered-pricing-block__price">
117 <?php
118 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
119 'price' => $real_price,
120 ) ) ) );
121 ?>
122 </div>
123 <div class="tiered-pricing-block__quantity">
124 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
125 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?></span>
126 <?php if ( $minimum > 1 ) : ?>
127 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
128 <?php else : ?>
129 <?php echo esc_html( $settings['quantity_measurement_singular'] ); ?>
130 <?php endif; ?>
131 <?php else : ?>
132 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $price_rules )[0] - 1 ) ); ?></span>
133 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
134 <?php endif; ?>
135 </div>
136
137 </div>
138 </div>
139 <?php $tptTierRows[] = ob_get_clean(); ?>
140
141 <?php $iterator = new ArrayIterator( $price_rules ); ?>
142
143 <?php while ( $iterator->valid() ) : ob_start(); ?>
144 <?php
145 $currentPrice = $iterator->current();
146 $currentQuantity = $iterator->key();
147
148 if ( 'percentage' === $pricing_type ) {
149 $discountAmount = $currentPrice;
150 } else {
151 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
152 $pricing_rule->getTierPrice( $currentQuantity, false ) );
153 }
154
155 $iterator->next();
156
157 if ( $iterator->valid() ) {
158 $quantity = number_format_i18n( $currentQuantity );
159
160 if ( (int) $iterator->key() - 1 !== (int) $currentQuantity && 'range' === $settings['quantity_type'] ) {
161 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
162 }
163 } else {
164 $quantity = number_format_i18n( $currentQuantity );
165
166 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
167 $currentQuantity, $pricing_rule, 'blocks' );
168 }
169
170 $quantity = $quantity . ' ' . $settings['quantity_measurement_plural'];
171
172 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
173
174 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
175 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
176 ) );
177
178 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
179 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
180 ) );
181
182 ?>
183
184 <div class="tiered-pricing-block"
185 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
186 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
187 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
188 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>">
189
190 <?php if ( $settings['show_discount_column'] && $discountAmount > 0 ) : ?>
191 <div class="tiered-pricing-block__discount">
192
193 <span class="tiered-pricing-block__price-discount">
194 <?php
195 echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings, 'off' ) );
196 ?>
197 </span>
198 </div>
199 <?php endif; ?>
200
201 <div class="tiered-pricing-block-inner">
202
203 <?php
204 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $currentQuantity, array(
205 'id' => $id,
206 'style' => '3',
207 ) );
208 ?>
209
210 <div class="tiered-pricing-block__price">
211 <span>
212 <?php
213 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity,
214 $product_id ) ) );
215 ?>
216 </span>
217 </div>
218 <div class="tiered-pricing-block__quantity"><?php echo esc_html( $quantity ); ?></div>
219 </div>
220
221 </div>
222 <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
223 <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
224
225 <?php do_action( 'tiered_pricing_table/blocks/blocks', $pricing_rule, $settings ); ?>
226 </div>
227
228 <?php do_action( 'tiered_pricing_table/blocks/after_blocks', $pricing_rule ); ?>
229 </div>
230
231 <style>
232 <?php
233 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
234 echo esc_attr('#' . $id) . ' .tiered-pricing-block {cursor: pointer; }';
235 }
236 ?>
237
238 <?php echo esc_attr('#' . $id); ?>
239 .tiered-pricing--active {
240 border-color: <?php echo esc_attr($settings['active_tier_color']); ?> !important;
241 }
242
243 .tiered-pricing-blocks--style-3 .tiered-pricing-block {
244 border-color: <?php echo esc_html(Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.3 )); ?>;
245 }
246
247 .tiered-pricing-blocks--style-3 .tiered-pricing-block__quantity {
248 line-height: normal;
249 font-size: .8em;
250 }
251
252 .tiered-pricing-blocks--style-3 .tiered-pricing-block__price {
253 line-height: normal;
254 font-weight: 600;
255 }
256
257 .tiered-pricing-blocks--style-3 .tiered-pricing-block__discount {
258 position: absolute;
259 background: <?php echo esc_html(Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.85 )); ?>;
260 color: #fff;
261 top: 0;
262 left: 50%;
263 translate: -50% -50%;
264 font-weight: 600;
265 width: max-content;
266 white-space: nowrap;
267 line-height: 1.3;
268 padding: 2px 8px;
269 border-radius: 3px;
270 display: flex;
271 align-items: center;
272 justify-content: center;
273 }
274
275 .tiered-pricing-blocks--style-3 .tiered-pricing--active .tiered-pricing-block__discount {
276 background: <?php echo esc_html( $settings['active_tier_color']); ?>;
277 }
278
279 </style>
280 <?php endif; ?>