PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
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-style-2.php

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

299 lines 11.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\PricingTable;
20 use TierPricingTable\PricingRule;
21 use TierPricingTable\Settings\Settings;
22
23 if ( ! defined( 'WPINC' ) ) {
24 die;
25 }
26
27 $sale_price = $product->get_sale_price();
28
29 if ( $sale_price ) {
30 $sale_price = wc_get_price_to_display( $product, array(
31 'price' => $sale_price,
32 ) );
33 }
34
35 $regular_price = wc_get_price_to_display( $product, array(
36 'price' => $product->get_regular_price(),
37 ) );
38
39 $price = wc_get_price_to_display( $product, array(
40 'price' => $product->get_price(),
41 ) );
42
43 $price_incl_taxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
44 'price' => $real_price,
45 ) );
46
47 $price_excl_taxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
48 'price' => $real_price,
49 ) );
50
51 ?>
52
53 <?php if ( ! empty( $pricing_rule->getRules() ) ) : ?>
54 <div class="clear"></div>
55
56 <div class="tiered-pricing-wrapper">
57 <?php if ( ! empty( $settings['title'] ) ) : ?>
58 <h3 style="clear:both; margin: 20px 0; font-weight: 600;"><?php echo esc_attr( $settings['title'] ); ?></h3>
59 <?php endif; ?>
60
61 <?php do_action( 'tiered_pricing_table/tiered_pricing/before', $pricing_rule ); ?>
62
63 <?php
64 $columns = 0;
65 if ( $settings['quantity_column_title'] ) $columns++;
66 if ( $settings['discount_column_title'] ) $columns++;
67 if ( $settings['price_column_title'] ) $columns++;
68
69 // Detect custom columns via output buffering
70 ob_start();
71 do_action( 'tiered_pricing_table/tiered_pricing/header_columns', $pricing_rule );
72 $custom_head = ob_get_clean();
73 $custom_columns_count = substr_count($custom_head, '<th');
74 $columns += $custom_columns_count;
75 ?>
76
77 <div class="tiered-pricing-table tiered-pricing-table--styled tiered-pricing-table--style-2 <?php echo (isset($settings['compact_layout']) && $settings['compact_layout'] === 'yes') ? 'tiered-pricing-table--slim' : ''; ?>"
78
79 <?php echo PricingTable::layoutStyleAttribute( $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper ?>
80 id="<?php echo esc_attr( $id ); ?>"
81 data-tiered-pricing-table
82 data-product-id="<?php echo esc_attr( $product_id ); ?>"
83 data-price-rules="<?php echo esc_attr( json_encode( $pricing_rule->getRules() ) ); ?>"
84 data-minimum="<?php echo esc_attr( $minimum ); ?>"
85 data-product-name="<?php echo esc_attr( $product_name ); ?>"
86 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
87 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
88 data-price="<?php echo esc_attr( $price ); ?>"
89 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
90 >
91 <div class="tiered-pricing-table-header" style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
92 <?php if ( $settings['quantity_column_title'] ) : ?>
93 <div><?php echo esc_attr( $settings['quantity_column_title'] ); ?></div>
94 <?php endif; ?>
95
96 <?php if ( $settings['discount_column_title'] ) : ?>
97 <div><?php echo esc_attr( ( $settings['discount_column_title'] ) ); ?></div>
98 <?php endif; ?>
99
100 <?php if ( $settings['price_column_title'] ) : ?>
101 <div><?php echo esc_attr( $settings['price_column_title'] ); ?></div>
102 <?php endif; ?>
103
104 <?php echo wp_kses_post( str_replace(['<th', '</th>'], ['<div', '</div>'], $custom_head) ); ?>
105 </div>
106
107 <div class="tiered-pricing-table-body">
108 <?php $tptTierRows = array(); ob_start(); ?>
109 <div class="tiered-pricing-table-row tiered-pricing--active"
110 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
111 data-tiered-price="<?php echo esc_attr( $price ); ?>"
112 data-tiered-price-exclude-taxes="<?php echo esc_attr( $price_excl_taxes ); ?>"
113 data-tiered-price-include-taxes="<?php echo esc_attr( $price_incl_taxes ); ?>"
114 style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
115
116 <?php if ( $settings['quantity_column_title'] ) : ?>
117 <div>
118 <?php if ( 1 >= array_keys( $pricing_rule->getRules() )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
119 <span>
120 <span class="tiered-pricing-table-row-qty">
121 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?>
122 </span>
123 <span class="tiered-pricing-table-row-qty-unit">
124 <?php echo esc_attr( ' ' . ( $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] ) ); ?>
125 </span>
126 </span>
127 <?php else : ?>
128 <span>
129 <span class="tiered-pricing-table-row-qty">
130 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $pricing_rule->getRules() )[0] - 1 ) ); ?>
131 </span>
132 <span class="tiered-pricing-table-row-qty-unit">
133 <?php echo esc_attr( ' ' . $settings['quantity_measurement_plural'] ); ?>
134 </span>
135 </span>
136 <?php endif; ?>
137
138 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $minimum, array(
139 'id' => $id,
140 'style' => 'default',
141 ) ); ?>
142 </div>
143 <?php endif; ?>
144
145 <?php if ( $settings['discount_column_title'] ) : ?>
146
147 <?php
148 $discountAmount = 0;
149 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
150 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
151 $product->get_sale_price() );
152 }
153 ?>
154
155 <div>
156 <?php if ( $discountAmount > 0 ) : ?>
157 <span class="tiered-pricing-table-row-discount"><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings ) ); ?></span>
158 <?php else : ?>
159 <span class="tiered-pricing-table-row-discount--empty">—</span>
160 <?php endif; ?>
161 </div>
162 <?php endif; ?>
163
164 <?php if ( $settings['price_column_title'] ) : ?>
165 <div class="tiered-pricing-table-row-price">
166 <?php
167 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ),
168 array( 'price' => $real_price, ) ) ) );
169 ?>
170 </div>
171 <?php endif; ?>
172
173 <?php
174 ob_start();
175 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, null );
176 $custom_cols = ob_get_clean();
177 echo wp_kses_post( str_replace(['<td', '</td>'], ['<div', '</div>'], $custom_cols) );
178 ?>
179 </div>
180 <?php $tptTierRows[] = ob_get_clean(); ?>
181
182 <?php $iterator = new ArrayIterator( $pricing_rule->getRules() ); ?>
183
184 <?php while ( $iterator->valid() ) : ob_start(); ?>
185 <?php
186 $currentPrice = $iterator->current();
187 $currentQuantity = $iterator->key();
188
189 $iterator->next();
190
191 if ( $pricing_rule->getType() === 'percentage' ) {
192 $discountAmount = $currentPrice;
193 } else {
194 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
195 $pricing_rule->getTierPrice( $currentQuantity, false ) );
196 }
197
198 $quantity = number_format_i18n( $currentQuantity );
199
200 if ( $iterator->valid() ) {
201
202 if ( intval( $iterator->key() - 1 != $currentQuantity ) && 'range' === $settings['quantity_type'] ) {
203 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
204 }
205
206 } else {
207 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
208 $currentQuantity, $pricing_rule, 'table' );
209 }
210
211 $quantityUnit = $settings['quantity_measurement_plural'];
212
213 $currentProductPrice = $pricing_rule->getTierPrice( $currentQuantity );
214
215 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
216 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
217 ) );
218
219 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
220 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
221 ) );
222
223 ?>
224 <div class="tiered-pricing-table-row" data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
225 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
226 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
227 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>"
228 style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
229
230 <?php if ( $settings['quantity_column_title'] ) : ?>
231 <div>
232 <span class="tiered-pricing-table-row-qty"><?php echo esc_attr( $quantity ); ?></span>
233 <span class="tiered-pricing-table-row-qty-unit"> <?php echo esc_attr( $quantityUnit ); ?></span>
234 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $currentQuantity,
235 array(
236 'id' => $id,
237 'style' => 'default',
238 ) ); ?>
239 </div>
240 <?php endif; ?>
241
242 <?php if ( $settings['discount_column_title'] ) : ?>
243 <div>
244 <?php if ( $discountAmount > 0 ) : ?>
245 <span class="tiered-pricing-table-row-discount"><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings ) ); ?></span>
246 <?php else : ?>
247 <span class="tiered-pricing-table-row-discount--empty">—</span>
248 <?php endif; ?>
249 </div>
250 <?php endif; ?>
251
252 <?php if ( $settings['price_column_title'] ) : ?>
253 <div class="tiered-pricing-table-row-price">
254 <?php
255 echo wp_kses_post( wc_price( $pricing_rule->getTierPrice( $currentQuantity ) ) );
256 ?>
257 </div>
258 <?php endif; ?>
259
260 <?php
261 ob_start();
262 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, $currentQuantity );
263 $custom_cols = ob_get_clean();
264 echo wp_kses_post( str_replace(['<td', '</td>'], ['<div', '</div>'], $custom_cols) );
265 ?>
266 </div>
267
268 <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
269 <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
270 <?php do_action( 'tiered_pricing_table/tiered_pricing/rows', $pricing_rule, $settings, 'tiered-pricing-table-style-2' ); ?>
271 <?php do_action( 'tiered_pricing_table/table/tfoot', $pricing_rule, $settings, 'tiered-pricing-table-style-2' ); ?>
272 </div>
273 </div>
274
275 <?php do_action( 'tiered_pricing_table/tiered_pricing/after', $pricing_rule, $product_id ); ?>
276 </div>
277
278 <style>
279 <?php
280 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
281 echo esc_attr('#' . $id) . ' .tiered-pricing-table-row { cursor: pointer; }';
282 echo esc_attr('#' . $id) . ' .tiered-pricing-table-row:not(.tiered-pricing--active):hover { box-shadow: 0 6px 12px rgba(0,0,0,0.05); transform: translateY(-2px); border-color: #e5e7eb; }';
283 }
284 ?>
285
286 <?php echo esc_attr('#' . $id); ?> .tiered-pricing--active {
287 border: 2px solid <?php echo esc_attr($settings['active_tier_color']); ?> !important;
288 box-shadow: 0 4px 12px <?php echo esc_attr( Settings::hex2rgba( $settings['active_tier_color'], 0.12 ) ); ?> !important;
289 }
290
291 <?php if ( ! empty( $settings['discount_badge_color'] ) ) : ?>
292 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing-table-row-discount {
293 background-color: <?php echo esc_attr( Settings::hex2rgba( $settings['discount_badge_color'], 0.12 ) ); ?>;
294 color: <?php echo esc_attr( $settings['discount_badge_color'] ); ?>;
295 }
296 <?php endif; ?>
297 </style>
298 <?php endif; ?>
299