PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.4
Tiered Pricing Table for WooCommerce v7.1.4
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-plain-text.php

tiered-pricing-plain-text.php in Tiered Pricing Table for WooCommerce 7.1.4, at views/frontend/tiered-pricing-plain-text.php

220 lines 7.2 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
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 if ( ! function_exists( 'tptParsePlainText' ) ) {
42 function tptParsePlainText( $text, $quantity, $discount = null, $price = null, $base_unit_name = null ) {
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_price}' => $price ? wc_price( $price ) : '',
48 '{tp_base_unit_name}' => $base_unit_name,
49 ) );
50 }
51 }
52 ?>
53 <?php if ( ! empty( $price_rules ) ) : ?>
54
55 <div class="tiered-pricing-wrapper">
56 <?php if ( ! empty( $settings['title'] ) ) : ?>
57 <h3 style="clear:both; margin: 20px 0;"><?php echo esc_attr( $settings['title'] ); ?></h3>
58 <?php endif; ?>
59
60 <ul class="tiered-pricing-plain-texts"
61 id="<?php echo esc_attr( $id ); ?>"
62 data-product-id="<?php echo esc_attr( $product_id ); ?>"
63 data-price-rules="<?php echo esc_attr( htmlspecialchars( json_encode( $price_rules ) ) ); ?>"
64 data-minimum="<?php echo esc_attr( $minimum ); ?>"
65 data-product-name="<?php echo esc_attr( $product_name ); ?>"
66 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
67 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
68 data-price="<?php echo esc_attr( $price ); ?>"
69 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
70 >
71 <li class="tiered-pricing-plain-text tiered-pricing--active tiered-pricing-plain-text--default"
72 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
73 data-tiered-price="<?php echo esc_attr( $price ); ?>"
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
90 $discountAmount = 0;
91 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
92 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
93 $product->get_sale_price() );
94 }
95 ?>
96
97 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
98 <?php
99 $quantity = esc_attr( number_format_i18n( $minimum ) . ' ' );
100 $baseUnitName = $settings['quantity_measurement_singular'];
101 ?>
102 <?php else : ?>
103 <?php
104 $quantity = esc_attr( number_format_i18n( $minimum ) . ' - ' . number_format_i18n( array_keys( $price_rules )[0] - 1 ) . ' ' );
105 $baseUnitName = $settings['quantity_measurement_plural'];
106 ?>
107 <?php endif; ?>
108
109 <?php if ( $discountAmount > 0 ) : ?>
110 <?php
111 echo wp_kses_post( tptParsePlainText( $settings['plain_text_option_text'], $quantity,
112 $discountAmount, $price, $baseUnitName ) );
113 ?>
114 <?php else : ?>
115 <?php
116 echo wp_kses_post( tptParsePlainText( $settings['plain_text_default_option_text'], $quantity, null,
117 $price, $baseUnitName ) );
118 ?>
119 <?php endif; ?>
120
121 <?php
122 do_action( 'tiered_pricing_table/plain-text/label', $pricing_rule, $minimum, array(
123 'id' => $id,
124 'style' => 'default',
125 ) );
126 ?>
127 </li>
128
129 <?php $iterator = new ArrayIterator( $price_rules ); ?>
130
131 <?php while ( $iterator->valid() ) : ?>
132 <?php
133 $currentPrice = $iterator->current();
134 $currentQuantity = $iterator->key();
135
136 if ( 'percentage' === $pricing_type ) {
137 $discountAmount = $currentPrice;
138 } else {
139 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
140 $pricing_rule->getTierPrice( $currentQuantity, false ) );
141 }
142
143 $iterator->next();
144
145 if ( $iterator->valid() ) {
146 $quantity = $currentQuantity;
147
148 if ( intval( $iterator->key() - 1 != $currentQuantity ) ) {
149
150 $quantity = number_format_i18n( $quantity );
151
152 if ( 'range' === $settings['quantity_type'] ) {
153 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
154 }
155 }
156 } else {
157 $quantity = number_format_i18n( $currentQuantity );
158
159 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
160 $currentQuantity, $pricing_rule, 'blocks' );
161 }
162
163 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
164
165 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
166 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
167 ) );
168
169 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
170 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
171 ) );
172
173 ?>
174
175 <li class="tiered-pricing-plain-text"
176 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
177 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
178 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
179 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>">
180
181 <?php
182
183 echo wp_kses_post( tptParsePlainText( $settings['plain_text_option_text'], $quantity,
184 round( $discountAmount, 2 ), $currentProductPrice,
185 $settings['quantity_measurement_plural'] ) );
186 ?>
187
188 <?php
189 do_action( 'tiered_pricing_table/plain-text/label', $pricing_rule, $currentQuantity, array(
190 'id' => $id,
191 'style' => 'default',
192 ) );
193 ?>
194 </li>
195 <?php endwhile; ?>
196
197 <?php do_action( 'tiered_pricing_table/plain-text/line', $pricing_rule, $settings ); ?>
198 </ul>
199
200 <?php do_action( 'tiered_pricing_table/plain-text/after_lines', $pricing_rule, $settings ); ?>
201 </div>
202
203 <style>
204 <?php
205 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code() ) {
206 echo esc_html("#{$id} .tiered-pricing-plain-text {cursor: pointer; }");
207 }
208
209 if ( ! $settings['plain_text_show_default_option'] ) {
210 echo esc_html("#{$id} .tiered-pricing-plain-text--default { display: none }");
211 }
212
213 echo esc_html( "#{$id} .tiered-pricing--active {
214 color: {$settings['active_tier_color']};
215 }");
216
217 ?>
218
219 </style>
220 <?php endif; ?>