PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.7
Tiered Pricing Table for WooCommerce v7.1.7
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-options.php

tiered-pricing-options.php in Tiered Pricing Table for WooCommerce 7.1.7, at views/frontend/tiered-pricing-options.php

369 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use TierPricingTable\CalculationLogic;
4 use TierPricingTable\PriceManager;
5 use TierPricingTable\PricingRule;
6 use TierPricingTable\Settings\Settings;
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 $sale_price = $product->get_sale_price();
25 if ( $sale_price ) {
26 $sale_price = wc_get_price_to_display( $product, array(
27 'price' => $sale_price,
28 ) );
29 }
30 $regular_price = wc_get_price_to_display( $product, array(
31 'price' => $product->get_regular_price(),
32 ) );
33 $price = wc_get_price_to_display( $product, array(
34 'price' => $product->get_price(),
35 ) );
36 if ( !function_exists( 'tptParseOptionText' ) ) {
37 function tptParseOptionText(
38 $text,
39 $quantity,
40 $discount = null,
41 $base_unit_name = null
42 ) {
43 return strtr( $text, array(
44 '{tp_quantity}' => $quantity,
45 '{tp_discount}' => $discount,
46 '{tp_rounded_discount}' => ( !is_null( $discount ) ? round( $discount ) : 0 ),
47 '{tp_base_unit_name}' => $base_unit_name,
48 ) );
49 }
50
51 }
52 if ( !empty( $price_rules ) ) {
53 ?>
54
55 <div class="tiered-pricing-wrapper">
56 <?php
57 if ( !empty( $settings['title'] ) ) {
58 ?>
59 <h3 style="clear:both; margin: 20px 0;"><?php
60 echo esc_attr( $settings['title'] );
61 ?></h3>
62 <?php
63 }
64 ?>
65
66 <div class="tiered-pricing-options <?php
67 echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ? 'tiered-pricing-options--slim' : '' );
68 ?>"
69 id="<?php
70 echo esc_attr( $id );
71 ?>"
72 data-product-id="<?php
73 echo esc_attr( $product_id );
74 ?>"
75 data-price-rules="<?php
76 echo esc_attr( htmlspecialchars( json_encode( $price_rules ) ) );
77 ?>"
78 data-minimum="<?php
79 echo esc_attr( $minimum );
80 ?>"
81 data-product-name="<?php
82 echo esc_attr( $product_name );
83 ?>"
84 data-regular-price="<?php
85 echo esc_attr( $regular_price );
86 ?>"
87 data-sale-price="<?php
88 echo esc_attr( $sale_price );
89 ?>"
90 data-price="<?php
91 echo esc_attr( $price );
92 ?>"
93 data-product-price-suffix="<?php
94 echo esc_attr( $product->get_price_suffix() );
95 ?>"
96 >
97 <div class="tiered-pricing-option tiered-pricing--active tiered-pricing-option--default"
98 data-tiered-quantity="<?php
99 echo esc_attr( $minimum );
100 ?>"
101 data-tiered-price="<?php
102 echo esc_attr( $price );
103 ?>"
104 data-tiered-price-exclude-taxes="
105 <?php
106 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
107 'price' => $real_price,
108 ) ) );
109 ?>
110 "
111 data-tiered-price-include-taxes="
112 <?php
113 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
114 'price' => $real_price,
115 ) ) );
116 ?>
117 "
118 >
119 <div class="tiered-pricing-option__checkbox">
120 <div class="tiered-pricing-option-checkbox tiered-pricing-option-checkbox--active"></div>
121 </div>
122
123 <?php
124 $discountAmount = 0;
125 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
126 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(), $product->get_sale_price() );
127 }
128 ?>
129
130 <div class="tiered-pricing-option__quantity">
131 <?php
132 if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) {
133 ?>
134 <?php
135 $quantity = esc_attr( number_format_i18n( $minimum ) . ' ' );
136 $baseUnitName = $settings['quantity_measurement_singular'];
137 ?>
138 <?php
139 } else {
140 ?>
141 <?php
142 $quantity = esc_attr( number_format_i18n( $minimum ) . ' - ' . number_format_i18n( array_keys( $price_rules )[0] - 1 ) . ' ' );
143 $baseUnitName = $settings['quantity_measurement_plural'];
144 ?>
145 <?php
146 }
147 ?>
148
149 <?php
150 if ( $discountAmount > 0 ) {
151 ?>
152 <?php
153 echo wp_kses_post( tptParseOptionText(
154 $settings['options_option_text'],
155 $quantity,
156 $discountAmount,
157 $baseUnitName
158 ) );
159 ?>
160 <?php
161 } else {
162 ?>
163 <?php
164 echo wp_kses_post( tptParseOptionText(
165 $settings['options_default_option_text'],
166 $quantity,
167 null,
168 $baseUnitName
169 ) );
170 ?>
171 <?php
172 }
173 ?>
174
175 </div>
176
177 <?php
178 do_action(
179 'tiered_pricing_table/options/label',
180 $pricing_rule,
181 $minimum,
182 array(
183 'id' => $id,
184 'style' => 'default',
185 )
186 );
187 ?>
188
189 <div class="tiered-pricing-option__pricing">
190 <div class="tiered-pricing-option-price">
191
192 <?php
193 if ( $discountAmount > 0 ) {
194 ?>
195 <div class="tiered-pricing-option-price__original">
196 <del>
197 <?php
198 echo wp_kses_post( wc_price( $regular_price ) );
199 ?>
200 </del>
201 </div>
202 <?php
203 }
204 ?>
205
206 <div class="tiered-pricing-option-price__discounted">
207 <?php
208 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
209 'price' => $real_price,
210 ) ) ) );
211 ?>
212 </div>
213
214 </div>
215
216 <?php
217 ?>
218 </div>
219 </div>
220
221 <?php
222 $iterator = new ArrayIterator($price_rules);
223 ?>
224
225 <?php
226 while ( $iterator->valid() ) {
227 ?>
228 <?php
229 $currentPrice = $iterator->current();
230 $currentQuantity = $iterator->key();
231 if ( 'percentage' === $pricing_type ) {
232 $discountAmount = $currentPrice;
233 } else {
234 $discountAmount = PriceManager::calculateDiscount( ( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price() ), $pricing_rule->getTierPrice( $currentQuantity, false ) );
235 }
236 $iterator->next();
237 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 }
244 }
245 } else {
246 $quantity = number_format_i18n( $currentQuantity );
247 $quantity .= apply_filters(
248 'tiered_pricing_table/tiered_pricing/last_tier_postfix',
249 '+',
250 $currentQuantity,
251 $pricing_rule,
252 'blocks'
253 );
254 }
255 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
256 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
257 'price' => PriceManager::getPriceByRules(
258 $currentQuantity,
259 $product_id,
260 null,
261 null,
262 false
263 ),
264 ) );
265 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
266 'price' => PriceManager::getPriceByRules(
267 $currentQuantity,
268 $product_id,
269 null,
270 null,
271 false
272 ),
273 ) );
274 ?>
275
276 <div class="tiered-pricing-option"
277 data-tiered-quantity="<?php
278 echo esc_attr( $currentQuantity );
279 ?>"
280 data-tiered-price="<?php
281 echo esc_attr( $currentProductPrice );
282 ?>"
283 data-tiered-price-exclude-taxes="<?php
284 echo esc_attr( $currentProductPriceExcludeTaxes );
285 ?>"
286 data-tiered-price-include-taxes="<?php
287 echo esc_attr( $currentProductPriceIncludeTaxes );
288 ?>">
289
290 <div class="tiered-pricing-option__checkbox">
291 <div class="tiered-pricing-option-checkbox"></div>
292 </div>
293 <div class="tiered-pricing-option__quantity">
294 <?php
295 echo wp_kses_post( tptParseOptionText(
296 $settings['options_option_text'],
297 $quantity,
298 round( $discountAmount, 2 ),
299 $settings['quantity_measurement_plural']
300 ) );
301 ?>
302 </div>
303
304 <?php
305 do_action(
306 'tiered_pricing_table/options/label',
307 $pricing_rule,
308 $currentQuantity,
309 array(
310 'id' => $id,
311 'style' => 'default',
312 )
313 );
314 ?>
315
316 <div class="tiered-pricing-option__pricing">
317 <div class="tiered-pricing-option-price">
318 <div class="tiered-pricing-option-price__original">
319 <del>
320 <?php
321 echo wp_kses_post( wc_price( wc_get_price_to_display( $product, array(
322 'price' => ( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $regular_price : $real_price ),
323 ) ) ) );
324 ?>
325 </del>
326 </div>
327 <div class="tiered-pricing-option-price__discounted">
328 <?php
329 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity, $product_id ) ) );
330 ?>
331 </div>
332 </div>
333
334 <?php
335 ?>
336 </div>
337 </div>
338 <?php
339 }
340 ?>
341
342 <?php
343 do_action( 'tiered_pricing_table/options/options', $pricing_rule, $settings );
344 ?>
345 </div>
346
347 <?php
348 do_action( 'tiered_pricing_table/options/after_options', $pricing_rule );
349 ?>
350 </div>
351
352 <style>
353 <?php
354 if ( !$settings['options_show_default_option'] ) {
355 echo esc_html( "#{$id} .tiered-pricing-option--default { display: none }" );
356 }
357 $backgroundColor = Settings::hex2rgba( $settings['active_tier_color'], 0.05 );
358 echo esc_html( "#{$id} .tiered-pricing--active .tiered-pricing-option-checkbox::after {\n\t\t\tbackground: {$settings['active_tier_color']};\n\t\t}" );
359 echo esc_html( "#{$id} .tiered-pricing--active .tiered-pricing-option-checkbox {\n\t\t\tborder-color: {$settings['active_tier_color']};\n\t\t}" );
360 echo esc_html( "#{$id} .tiered-pricing--active {\n\t\t\tborder-color: {$settings['active_tier_color']};\n\t\t\tbackground: {$backgroundColor};\n\t\t}" );
361 if ( !$settings['options_show_original_product_price'] ) {
362 echo esc_html( "#{$id} .tiered-pricing-option-price__original {\n\t\t\t\tdisplay: none\n\t\t\t}" );
363 echo esc_html( "#{$id} .tiered-pricing-option-total__original_total {\n\t\t\t\tdisplay: none\n\t\t\t}" );
364 }
365 ?>
366
367 </style>
368 <?php
369 }