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-6.php

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

316 lines 12.1 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'] ) {
66 $columns ++;
67 }
68 if ( $settings['discount_column_title'] ) {
69 $columns ++;
70 }
71 if ( $settings['price_column_title'] ) {
72 $columns ++;
73 }
74
75 // Detect custom columns via output buffering
76 ob_start();
77 do_action( 'tiered_pricing_table/tiered_pricing/header_columns', $pricing_rule );
78 $custom_head = ob_get_clean();
79 $custom_columns_count = substr_count( $custom_head, '<th' );
80 $columns += $custom_columns_count;
81 ?>
82
83 <div class="tiered-pricing-table tiered-pricing-table--styled tiered-pricing-table--style-6 <?php echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ) ? 'tiered-pricing-table--slim' : ''; ?>"
84
85 <?php echo PricingTable::layoutStyleAttribute( $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper ?>
86 id="<?php echo esc_attr( $id ); ?>"
87 data-tiered-pricing-table
88 data-product-id="<?php echo esc_attr( $product_id ); ?>"
89 data-price-rules="<?php echo esc_attr( json_encode( $pricing_rule->getRules() ) ); ?>"
90 data-minimum="<?php echo esc_attr( $minimum ); ?>"
91 data-product-name="<?php echo esc_attr( $product_name ); ?>"
92 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
93 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
94 data-price="<?php echo esc_attr( $price ); ?>"
95 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
96 >
97 <div class="tiered-pricing-table-header"
98 style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
99 <?php if ( $settings['quantity_column_title'] ) : ?>
100 <div><?php echo esc_attr( $settings['quantity_column_title'] ); ?></div>
101 <?php endif; ?>
102
103 <?php if ( $settings['discount_column_title'] ) : ?>
104 <div><?php echo esc_attr( ( $settings['discount_column_title'] ) ); ?></div>
105 <?php endif; ?>
106
107 <?php if ( $settings['price_column_title'] ) : ?>
108 <div><?php echo esc_attr( $settings['price_column_title'] ); ?></div>
109 <?php endif; ?>
110
111 <?php echo wp_kses_post( str_replace( [ '<th', '</th>' ], [ '<div', '</div>' ], $custom_head ) ); ?>
112 </div>
113
114 <div class="tiered-pricing-table-body">
115 <?php $tptTierRows = array(); ob_start(); ?>
116 <div class="tiered-pricing-table-row 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 style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
122
123 <?php if ( $settings['quantity_column_title'] ) : ?>
124 <div>
125 <?php if ( 1 >= array_keys( $pricing_rule->getRules() )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
126 <span>
127 <span class="tiered-pricing-table-row-qty">
128 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?>
129 </span>
130 <span class="tiered-pricing-table-row-qty-unit">
131 <?php echo esc_attr( ' ' . ( $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] ) ); ?>
132 </span>
133 </span>
134 <?php else : ?>
135 <span>
136 <span class="tiered-pricing-table-row-qty">
137 <?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $pricing_rule->getRules() )[0] - 1 ) ); ?>
138 </span>
139 <span class="tiered-pricing-table-row-qty-unit">
140 <?php echo esc_attr( ' ' . $settings['quantity_measurement_plural'] ); ?>
141 </span>
142 </span>
143 <?php endif; ?>
144
145 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $minimum, array(
146 'id' => $id,
147 'style' => 'default',
148 ) ); ?>
149 </div>
150 <?php endif; ?>
151
152 <?php if ( $settings['discount_column_title'] ) : ?>
153
154 <?php
155 $discountAmount = 0;
156 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
157 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
158 $product->get_sale_price() );
159 }
160 ?>
161
162 <div>
163 <?php if ( $discountAmount > 0 ) : ?>
164 <span class="tiered-pricing-table-row-discount"><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings ) ); ?></span>
165 <?php else : ?>
166 <span class="tiered-pricing-table-row-discount--empty">—</span>
167 <?php endif; ?>
168 </div>
169 <?php endif; ?>
170
171 <?php if ( $settings['price_column_title'] ) : ?>
172 <div class="tiered-pricing-table-row-price">
173 <?php
174 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ),
175 array( 'price' => $real_price, ) ) ) );
176 ?>
177 </div>
178 <?php endif; ?>
179
180 <?php
181 ob_start();
182 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, null );
183 $custom_cols = ob_get_clean();
184 echo wp_kses_post( str_replace( [ '<td', '</td>' ], [ '<div', '</div>' ], $custom_cols ) );
185 ?>
186 </div>
187 <?php $tptTierRows[] = ob_get_clean(); ?>
188
189 <?php $iterator = new ArrayIterator( $pricing_rule->getRules() ); ?>
190
191 <?php while ( $iterator->valid() ) : ob_start(); ?>
192 <?php
193 $currentPrice = $iterator->current();
194 $currentQuantity = $iterator->key();
195
196 $iterator->next();
197
198 if ( $pricing_rule->getType() === 'percentage' ) {
199 $discountAmount = $currentPrice;
200 } else {
201 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
202 $pricing_rule->getTierPrice( $currentQuantity, false ) );
203 }
204
205 $quantity = number_format_i18n( $currentQuantity );
206
207 if ( $iterator->valid() ) {
208
209 if ( intval( $iterator->key() - 1 != $currentQuantity ) && 'range' === $settings['quantity_type'] ) {
210 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
211 }
212
213 } else {
214 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
215 $currentQuantity, $pricing_rule, 'table' );
216 }
217
218 $quantityUnit = $settings['quantity_measurement_plural'];
219
220 $currentProductPrice = $pricing_rule->getTierPrice( $currentQuantity );
221
222 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
223 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
224 ) );
225
226 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
227 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
228 ) );
229
230 ?>
231 <div class="tiered-pricing-table-row"
232 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
233 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
234 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
235 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>"
236 style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
237
238 <?php if ( $settings['quantity_column_title'] ) : ?>
239 <div>
240 <span class="tiered-pricing-table-row-qty"><?php echo esc_attr( $quantity ); ?></span>
241 <span class="tiered-pricing-table-row-qty-unit"> <?php echo esc_attr( $quantityUnit ); ?></span>
242 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $currentQuantity,
243 array(
244 'id' => $id,
245 'style' => 'default',
246 ) ); ?>
247 </div>
248 <?php endif; ?>
249
250 <?php if ( $settings['discount_column_title'] ) : ?>
251 <div>
252 <?php if ( $discountAmount > 0 ) : ?>
253 <span class="tiered-pricing-table-row-discount"><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings ) ); ?></span>
254 <?php else : ?>
255 <span class="tiered-pricing-table-row-discount--empty">—</span>
256 <?php endif; ?>
257 </div>
258 <?php endif; ?>
259
260 <?php if ( $settings['price_column_title'] ) : ?>
261 <div class="tiered-pricing-table-row-price">
262 <?php
263 echo wp_kses_post( wc_price( $pricing_rule->getTierPrice( $currentQuantity ) ) );
264 ?>
265 </div>
266 <?php endif; ?>
267
268 <?php
269 ob_start();
270 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule,
271 $currentQuantity );
272 $custom_cols = ob_get_clean();
273 echo wp_kses_post( str_replace( [ '<td', '</td>' ], [ '<div', '</div>' ], $custom_cols ) );
274 ?>
275 </div>
276
277 <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
278 <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
279 <?php do_action( 'tiered_pricing_table/tiered_pricing/rows', $pricing_rule, $settings, 'tiered-pricing-table-style-6' ); ?>
280
281 <?php do_action( 'tiered_pricing_table/table/tfoot', $pricing_rule, $settings,
282 'tiered-pricing-table-style-6' ); ?>
283 </div>
284 </div>
285
286 <?php do_action( 'tiered_pricing_table/tiered_pricing/after', $pricing_rule, $product_id ); ?>
287 </div>
288
289 <style>
290 <?php echo esc_attr('#' . $id); ?>
291 .tiered-pricing-table-row:last-child {
292 border-bottom: none !important;
293 }
294
295 <?php
296 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
297 echo esc_attr('#' . $id) . ' .tiered-pricing-table-row { cursor: pointer; }';
298 echo esc_attr('#' . $id) . ' .tiered-pricing-table-row:not(.tiered-pricing--active):hover { background-color: #f3f4f6; }';
299 }
300 ?>
301
302 <?php echo esc_attr('#' . $id); ?>
303 .tiered-pricing--active {
304 background-color: <?php echo esc_attr( Settings::hex2rgba( $settings['active_tier_color'], 0.08 ) ); ?> !important;
305 border-left-color: <?php echo esc_attr( 'no' === ( $settings['active_tier_border'] ?? 'yes' ) ? 'transparent' : $settings['active_tier_color'] ); ?> !important;
306 }
307
308 <?php if ( ! empty( $settings['discount_badge_color'] ) ) : ?>
309 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing-table-row-discount {
310 background-color: <?php echo esc_attr( Settings::hex2rgba( $settings['discount_badge_color'], 0.1 ) ); ?>;
311 color: <?php echo esc_attr( $settings['discount_badge_color'] ); ?>;
312 }
313 <?php endif; ?>
314 </style>
315 <?php endif; ?>
316