PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.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 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 6.1.0, at views/frontend/tiered-pricing-options.php

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