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-horizontal-table.php

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

308 lines 10.9 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 $num_rows = 0;
50 if ( $settings['quantity_column_title'] ) $num_rows++;
51 if ( $settings['discount_column_title'] ) $num_rows++;
52 if ( $settings['price_column_title'] ) $num_rows++;
53
54 // Detect custom columns via output buffering
55 ob_start();
56 do_action( 'tiered_pricing_table/tiered_pricing/header_columns', $pricing_rule );
57 $custom_head = ob_get_clean();
58 $custom_columns_count = substr_count($custom_head, '<th');
59 $num_rows += $custom_columns_count;
60 ?>
61
62 <?php if ( ! empty( $pricing_rule->getRules() ) ) : ?>
63 <div class="clear"></div>
64
65 <div class="tiered-pricing-wrapper">
66 <?php if ( ! empty( $settings['title'] ) ) : ?>
67 <h3 style="clear:both; margin: 20px 0;"><?php echo esc_attr( $settings['title'] ); ?></h3>
68 <?php endif; ?>
69
70 <?php do_action( 'tiered_pricing_table/tiered_pricing/before', $pricing_rule ); ?>
71
72 <div class="tiered-pricing-horizontal-table"
73 id="<?php echo esc_attr( $id ); ?>"
74 data-tiered-pricing-table
75 data-product-id="<?php echo esc_attr( $product_id ); ?>"
76 data-price-rules="
77 <?php
78 echo esc_attr( htmlspecialchars( json_encode( $pricing_rule->getRules() ), ENT_QUOTES ) );
79 ?>
80 "
81 data-minimum="<?php echo esc_attr( $minimum ); ?>"
82 data-product-name="<?php echo esc_attr( $product_name ); ?>"
83 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
84 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
85 data-price="<?php echo esc_attr( $price ); ?>"
86 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>">
87
88 <div class="tiered-pricing-horizontal-table-column tiered-pricing-horizontal-table__labels">
89
90 <?php if ( $settings['quantity_column_title'] ) : ?>
91 <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--quantity">
92 <strong>
93 <?php echo esc_attr( $settings['quantity_column_title'] ); ?>
94 </strong>
95 </div>
96 <?php endif; ?>
97
98 <?php if ( $settings['discount_column_title'] ) : ?>
99 <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--discount">
100 <strong>
101 <?php echo esc_attr( ( $settings['discount_column_title'] ) ); ?>
102 </strong>
103 </div>
104 <?php endif; ?>
105
106 <?php if ( $settings['price_column_title'] ) : ?>
107 <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--price">
108 <strong>
109 <?php echo esc_attr( $settings['price_column_title'] ); ?>
110 </strong>
111 </div>
112 <?php endif; ?>
113
114 <?php echo str_replace(['<th', '</th>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_head); ?>
115 </div>
116 <div class="tiered-pricing-horizontal-table-column tiered-pricing-horizontal-table__values tiered-pricing--active"
117 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
118 data-tiered-price="<?php echo esc_attr( $price ); ?>"
119 data-tiered-price-exclude-taxes="<?php echo esc_attr( $price_excl_taxes ); ?>"
120 data-tiered-price-include-taxes="<?php echo esc_attr( $price_incl_taxes ); ?>">
121
122 <?php if ( $settings['quantity_column_title'] ) : ?>
123 <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--quantity">
124 <?php if ( 1 >= array_keys( $pricing_rule->getRules() )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
125 <span>
126 <span>
127 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?>
128 </span>
129 <span>
130 <?php echo esc_attr( ' ' . $settings['quantity_measurement_singular'] ); ?>
131 </span>
132 </span>
133 <?php else : ?>
134 <span>
135 <span>
136 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $pricing_rule->getRules() )[0] - 1 ) ); ?>
137 </span>
138 <span>
139 <?php echo esc_attr( ' ' . $settings['quantity_measurement_plural'] ); ?>
140 </span>
141 </span>
142 <?php endif; ?>
143
144 <?php
145 do_action( 'tiered_pricing_table/horizontal-table/label', $pricing_rule, $minimum, array(
146 'id' => $id,
147 'style' => 'default',
148 ) );
149 ?>
150
151 </div>
152 <?php endif; ?>
153
154 <?php if ( $settings['discount_column_title'] ) : ?>
155
156 <?php
157 $discountAmount = 0;
158 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
159 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
160 $product->get_sale_price() );
161 }
162 ?>
163
164 <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--discount">
165 <?php if ( $discountAmount > 0 ) : ?>
166 <span><?php echo esc_attr( round( $discountAmount, 2 ) ); ?> %</span>
167 <?php else : ?>
168 <span>—</span>
169 <?php endif; ?>
170 </div>
171 <?php endif; ?>
172
173 <?php if ( $settings['price_column_title'] ) : ?>
174 <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--price">
175 <?php
176 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ),
177 array( 'price' => $real_price, ) ) ) );
178 ?>
179 </div>
180 <?php endif; ?>
181
182 <?php
183 ob_start();
184 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, null );
185 $custom_cols = ob_get_clean();
186 echo str_replace(['<td', '</td>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_cols);
187 ?>
188 </div>
189
190 <?php $iterator = new ArrayIterator( $pricing_rule->getRules() ); ?>
191
192 <?php while ( $iterator->valid() ) : ?>
193 <?php
194 $currentPrice = $iterator->current();
195 $currentQuantity = $iterator->key();
196
197 $iterator->next();
198
199 if ( $pricing_rule->getType() === 'percentage' ) {
200 $discountAmount = $currentPrice;
201 } else {
202 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
203 $pricing_rule->getTierPrice( $currentQuantity, false ) );
204 }
205
206 $quantity = number_format_i18n( $currentQuantity );
207
208 if ( $iterator->valid() ) {
209
210 if ( intval( $iterator->key() - 1 != $currentQuantity ) && 'range' === $settings['quantity_type'] ) {
211 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
212 }
213
214 } else {
215 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
216 $currentQuantity, $pricing_rule, 'table' );
217 }
218
219 $quantity .= ' ' . $settings['quantity_measurement_plural'];
220
221 $currentProductPrice = $pricing_rule->getTierPrice( $currentQuantity );
222
223 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
224 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
225 ) );
226
227 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
228 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
229 ) );
230
231 ?>
232 <div class="tiered-pricing-horizontal-table-column tiered-pricing-horizontal-table__values"
233 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
234 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
235 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
236 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>">
237
238 <?php if ( $settings['quantity_column_title'] ) : ?>
239 <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--quantity">
240 <span><?php echo esc_attr( $quantity ); ?></span>
241
242 <?php
243 do_action( 'tiered_pricing_table/horizontal-table/label', $pricing_rule,
244 $currentQuantity, array(
245 'id' => $id,
246 'style' => 'default',
247 ) );
248 ?>
249 </div>
250 <?php endif; ?>
251
252 <?php if ( $settings['discount_column_title'] ) : ?>
253 <div
254 class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--discount">
255 <?php if ( $discountAmount > 0 ) : ?>
256 <span><?php echo esc_attr( round( $discountAmount, 2 ) ); ?> %</span>
257 <?php else : ?>
258 <span>—</span>
259 <?php endif; ?>
260 </div>
261 <?php endif; ?>
262
263 <?php if ( $settings['price_column_title'] ) : ?>
264 <div class="tiered-pricing-horizontal-table-cell tiered-pricing-horizontal-table-cell--price">
265 <?php
266 echo wp_kses_post( wc_price( $pricing_rule->getTierPrice( $currentQuantity ) ) );
267 ?>
268 </div>
269 <?php endif; ?>
270
271 <?php
272 ob_start();
273 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, $currentQuantity );
274 $custom_cols = ob_get_clean();
275 echo str_replace(['<td', '</td>'], ['<div class="tiered-pricing-horizontal-table-cell"', '</div>'], $custom_cols);
276 ?>
277 </div>
278 <?php endwhile; ?>
279 </div>
280
281 <?php do_action( 'tiered_pricing_table/tiered_pricing/after', $pricing_rule ); ?>
282 </div>
283
284 <style>
285 <?php echo esc_attr('#' . $id); ?>[data-tiered-pricing-table] {
286 display: grid;
287 grid-auto-flow: column;
288 grid-template-rows: repeat(<?php echo (int) $num_rows; ?>, auto);
289 }
290
291 <?php echo esc_attr('#' . $id); ?> .tiered-pricing-horizontal-table-column {
292 display: contents;
293 }
294
295 <?php
296 if ( $settings['clickable_rows']) {
297 echo esc_attr('#' . $id) . ' .tiered-pricing-horizontal-table__values { cursor: pointer; }';
298 echo esc_attr('#' . $id) . ' .tiered-pricing-horizontal-table__values:hover .tiered-pricing-horizontal-table-cell { background: #f5f5f5; }';
299 }
300 ?>
301
302 <?php echo esc_attr('#' . $id); ?> .tiered-pricing--active .tiered-pricing-horizontal-table-cell,
303 <?php echo esc_attr('#' . $id); ?> .tiered-pricing--active td {
304 background-color: <?php echo esc_attr($settings['active_tier_color']); ?> !important;
305 color: #fff;
306 }
307 </style>
308 <?php endif; ?>