PluginProbe
Tiered Pricing Table for WooCommerce / 6.4.0
Tiered Pricing Table for WooCommerce v6.4.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-table.php

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

271 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Available variables
4 *
5 * @var PricingRule $pricing_rule
6 * @var array $price_rules
7 * @var string $pricing_type
8 * @var string $real_price
9 * @var string $product_name
10 * @var WC_Product $product
11 * @var string $id
12 * @var int $product_id
13 * @var int $minimum
14 * @var array $settings
15 */
16
17 use TierPricingTable\CalculationLogic;
18 use TierPricingTable\PriceManager;
19 use TierPricingTable\PricingRule;
20
21 if ( ! defined( 'WPINC' ) ) {
22 die;
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 $price_incl_taxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
42 'price' => $real_price,
43 ) );
44
45 $price_excl_taxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
46 'price' => $real_price,
47 ) );
48
49 ?>
50
51 <?php if ( ! empty( $pricing_rule->getRules() ) ) : ?>
52 <div class="clear"></div>
53
54 <div class="tiered-pricing-wrapper">
55 <?php if ( ! empty( $settings['title'] ) ) : ?>
56 <h3 style="clear:both; margin: 20px 0;"><?php echo esc_attr( $settings['title'] ); ?></h3>
57 <?php endif; ?>
58
59 <?php do_action( 'tiered_pricing_table/tiered_pricing/before', $pricing_rule ); ?>
60
61 <table class="shop_table tiered-pricing-table"
62 id="<?php echo esc_attr( $id ); ?>"
63 data-tiered-pricing-table
64 data-product-id="<?php echo esc_attr( $product_id ); ?>"
65 data-price-rules="<?php echo esc_attr( json_encode( $pricing_rule->getRules() ) ); ?>"
66 data-minimum="<?php echo esc_attr( $minimum ); ?>"
67 data-product-name="<?php echo esc_attr( $product_name ); ?>"
68 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
69 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
70 data-price="<?php echo esc_attr( $price ); ?>"
71 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
72 >
73 <thead>
74 <tr>
75 <?php if ( $settings['quantity_column_title'] ) : ?>
76 <th>
77 <span class="nobr">
78 <?php echo esc_attr( $settings['quantity_column_title'] ); ?>
79 </span>
80 </th>
81 <?php endif; ?>
82
83 <?php if ( $settings['discount_column_title'] ) : ?>
84 <th>
85 <span class="nobr">
86 <?php echo esc_attr( ( $settings['discount_column_title'] ) ); ?>
87 </span>
88 </th>
89 <?php endif; ?>
90
91 <?php if ( $settings['price_column_title'] ) : ?>
92 <th>
93 <span class="nobr">
94 <?php echo esc_attr( $settings['price_column_title'] ); ?>
95 </span>
96 </th>
97 <?php endif; ?>
98
99 <?php do_action( 'tiered_pricing_table/tiered_pricing/header_columns', $pricing_rule ); ?>
100 </tr>
101 </thead>
102
103 <tbody>
104 <tr class="tiered-pricing--active"
105 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
106 data-tiered-price="<?php echo esc_attr( $price ); ?>"
107 data-tiered-price-exclude-taxes="<?php echo esc_attr( $price_excl_taxes ); ?>"
108 data-tiered-price-include-taxes="<?php echo esc_attr( $price_incl_taxes ); ?>">
109 <?php if ( $settings['quantity_column_title'] ) : ?>
110 <td>
111 <?php if ( 1 >= array_keys( $pricing_rule->getRules() )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
112 <span>
113 <span>
114 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?>
115 </span>
116 <span>
117 <?php echo esc_attr( ' ' . $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] ); ?>
118 </span>
119 </span>
120 <?php else : ?>
121 <span>
122 <span>
123 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $pricing_rule->getRules() )[0] - 1 ) ); ?>
124 </span>
125 <span>
126 <?php echo esc_attr( ' ' . $settings['quantity_measurement_plural'] ); ?>
127 </span>
128 </span>
129 <?php endif; ?>
130
131 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $minimum, array(
132 'id' => $id,
133 'style' => 'default',
134 ) ); ?>
135 </td>
136 <?php endif; ?>
137
138 <?php if ( $settings['discount_column_title'] ) : ?>
139
140 <?php
141 $discountAmount = 0;
142 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
143 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
144 $product->get_sale_price() );
145 }
146 ?>
147
148 <td>
149 <?php if ( $discountAmount > 0 ) : ?>
150 <span><?php echo esc_attr( round( $discountAmount, 2 ) ); ?> %</span>
151 <?php else : ?>
152 <span>—</span>
153 <?php endif; ?>
154 </td>
155 <?php endif; ?>
156
157 <?php if ( $settings['price_column_title'] ) : ?>
158 <td>
159 <?php
160 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ),
161 array( 'price' => $real_price, ) ) ) );
162 ?>
163 </td>
164 <?php endif; ?>
165
166 <?php do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, null ); ?>
167 </tr>
168
169 <?php $iterator = new ArrayIterator( $pricing_rule->getRules() ); ?>
170
171 <?php while ( $iterator->valid() ) : ?>
172 <?php
173 $currentPrice = $iterator->current();
174 $currentQuantity = $iterator->key();
175
176 $iterator->next();
177
178 if ( $pricing_rule->getType() === 'percentage' ) {
179 $discountAmount = $currentPrice;
180 } else {
181 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
182 $pricing_rule->getTierPrice( $currentQuantity, false ) );
183 }
184
185 $quantity = number_format_i18n( $currentQuantity );
186
187 if ( $iterator->valid() ) {
188
189 if ( intval( $iterator->key() - 1 != $currentQuantity ) && 'range' === $settings['quantity_type'] ) {
190 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
191 }
192
193 } else {
194 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
195 $currentQuantity, $pricing_rule, 'table' );
196 }
197
198 $quantity .= ' ' . $settings['quantity_measurement_plural'];
199
200 $currentProductPrice = $pricing_rule->getTierPrice( $currentQuantity );
201
202 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
203 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
204 ) );
205
206 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
207 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
208 ) );
209
210 ?>
211 <tr data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
212 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
213 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
214 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>">
215
216 <?php if ( $settings['quantity_column_title'] ) : ?>
217 <td>
218 <span><?php echo esc_attr( $quantity ); ?></span>
219 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $currentQuantity,
220 array(
221 'id' => $id,
222 'style' => 'default',
223 ) ); ?>
224 </td>
225 <?php endif; ?>
226
227 <?php if ( $settings['discount_column_title'] ) : ?>
228 <td>
229 <?php if ( $discountAmount > 0 ) : ?>
230 <span><?php echo esc_attr( round( $discountAmount, 2 ) ); ?> %</span>
231 <?php else : ?>
232 <span>—</span>
233 <?php endif; ?>
234 </td>
235 <?php endif; ?>
236
237 <?php if ( $settings['price_column_title'] ) : ?>
238 <td>
239 <?php
240 echo wp_kses_post( wc_price( $pricing_rule->getTierPrice( $currentQuantity ) ) );
241 ?>
242 </td>
243 <?php endif; ?>
244
245 <?php
246 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, $currentQuantity );
247 ?>
248 </tr>
249
250 <?php do_action( 'tiered_pricing_table/tiered_pricing/rows', $pricing_rule ); ?>
251
252 <?php endwhile; ?>
253 </tbody>
254 </table>
255
256 <?php do_action( 'tiered_pricing_table/tiered_pricing/after', $pricing_rule, $product_id ); ?>
257 </div>
258
259 <style>
260 <?php
261 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
262 echo esc_attr('#' . $id) . ' tbody tr {cursor: pointer; }';
263 }
264 ?>
265
266 <?php echo esc_attr('#' . $id); ?>
267 .tiered-pricing--active td {
268 background-color: <?php echo esc_attr($settings['active_tier_color']); ?> !important;
269 }
270 </style>
271 <?php endif; ?>