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

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

309 lines 13.3 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 // discount of every tier (percent), for the biggest discount
52 $tierDiscounts = array();
53 foreach ( $pricing_rule->getRules() as $tierQuantity => $tierPrice ) {
54 $tierDiscounts[ $tierQuantity ] = 'percentage' === $pricing_rule->getType()
55 ? (float) $tierPrice
56 : (float) PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
57 $pricing_rule->getTierPrice( $tierQuantity, false ) );
58 }
59 $maxDiscount = $tierDiscounts ? max( $tierDiscounts ) : 0;
60
61 ?>
62
63 <?php if ( ! empty( $pricing_rule->getRules() ) ) : ?>
64 <div class="clear"></div>
65
66 <div class="tiered-pricing-wrapper">
67 <?php if ( ! empty( $settings['title'] ) ) : ?>
68 <h3 style="clear:both; margin: 20px 0; font-weight: 600;"><?php echo esc_attr( $settings['title'] ); ?></h3>
69 <?php endif; ?>
70
71 <?php do_action( 'tiered_pricing_table/tiered_pricing/before', $pricing_rule ); ?>
72
73 <?php
74 $columns = 0;
75 if ( $settings['quantity_column_title'] ) $columns++;
76 if ( $settings['discount_column_title'] ) $columns++;
77 if ( $settings['price_column_title'] ) $columns++;
78
79 // Detect custom columns via output buffering
80 ob_start();
81 do_action( 'tiered_pricing_table/tiered_pricing/header_columns', $pricing_rule );
82 $custom_head = ob_get_clean();
83 $columns += substr_count( $custom_head, '<th' );
84 ?>
85
86 <div class="tiered-pricing-table tiered-pricing-table--styled tiered-pricing-table--style-5 <?php echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ) ? 'tiered-pricing-table--slim' : ''; ?>"
87
88 <?php echo PricingTable::layoutStyleAttribute( $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper ?>
89 id="<?php echo esc_attr( $id ); ?>"
90 data-tiered-pricing-table
91 data-product-id="<?php echo esc_attr( $product_id ); ?>"
92 data-price-rules="<?php echo esc_attr( json_encode( $pricing_rule->getRules() ) ); ?>"
93 data-minimum="<?php echo esc_attr( $minimum ); ?>"
94 data-product-name="<?php echo esc_attr( $product_name ); ?>"
95 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
96 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
97 data-price="<?php echo esc_attr( $price ); ?>"
98 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
99 >
100 <div class="tiered-pricing-table-header" style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
101 <?php if ( $settings['quantity_column_title'] ) : ?>
102 <div class="tiered-pricing-table-header-qty"><?php echo esc_attr( $settings['quantity_column_title'] ); ?></div>
103 <?php endif; ?>
104
105 <?php if ( $settings['discount_column_title'] ) : ?>
106 <div class="tiered-pricing-table-header-discount"><?php echo esc_attr( $settings['discount_column_title'] ); ?></div>
107 <?php endif; ?>
108
109 <?php if ( $settings['price_column_title'] ) : ?>
110 <div class="tiered-pricing-table-header-price"><?php echo esc_attr( $settings['price_column_title'] ); ?></div>
111 <?php endif; ?>
112
113 <?php echo wp_kses_post( str_replace( array( '<th', '</th>' ), array( '<div', '</div>' ), $custom_head ) );?>
114 </div>
115
116 <div class="tiered-pricing-table-body">
117 <?php $tptTierRows = array(); ob_start(); ?>
118 <div class="tiered-pricing-table-row tiered-pricing--active"
119 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
120 data-tiered-price="<?php echo esc_attr( $price ); ?>"
121 data-tiered-price-exclude-taxes="<?php echo esc_attr( $price_excl_taxes ); ?>"
122 data-tiered-price-include-taxes="<?php echo esc_attr( $price_incl_taxes ); ?>"
123 style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
124
125 <?php if ( $settings['quantity_column_title'] ) : ?>
126 <div>
127 <?php if ( 1 >= array_keys( $pricing_rule->getRules() )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
128 <span>
129 <span class="tiered-pricing-table-row-qty"><?php echo esc_attr( number_format_i18n( $minimum ) ); ?></span>
130 <span class="tiered-pricing-table-row-qty-unit"><?php echo esc_attr( ' ' . ( $minimum > 1 ? $settings['quantity_measurement_plural'] : $settings['quantity_measurement_singular'] ) ); ?></span>
131 </span>
132 <?php else : ?>
133 <span>
134 <span class="tiered-pricing-table-row-qty"><?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $pricing_rule->getRules() )[0] - 1 ) ); ?></span>
135 <span class="tiered-pricing-table-row-qty-unit"><?php echo esc_attr( ' ' . $settings['quantity_measurement_plural'] ); ?></span>
136 </span>
137 <?php endif; ?>
138
139 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $minimum, array(
140 'id' => $id,
141 'style' => 'default',
142 ) ); ?>
143 </div>
144 <?php endif; ?>
145
146 <?php if ( $settings['discount_column_title'] ) : ?>
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 <div>
155 <?php if ( $discountAmount > 0 ) : ?>
156 <span class="tiered-pricing-table-row-saving">
157 <span class="tiered-pricing-table-row-bar"><i style="width: <?php echo esc_attr( $maxDiscount > 0 ? min( 100, round( $discountAmount / $maxDiscount * 100 ) ) : 0 ); ?>%"></i></span>
158 <span class="tiered-pricing-table-row-discount"><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings ) ); ?></span>
159 </span>
160 <?php else : ?>
161 <span class="tiered-pricing-table-row-saving">
162 <span class="tiered-pricing-table-row-bar"><i style="width: 0"></i></span>
163 <span class="tiered-pricing-table-row-discount tiered-pricing-table-row-discount--empty">&mdash;</span>
164 </span>
165 <?php endif; ?>
166 </div>
167 <?php endif; ?>
168
169 <?php if ( $settings['price_column_title'] ) : ?>
170 <div class="tiered-pricing-table-row-price">
171 <?php
172 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ),
173 array( 'price' => $real_price ) ) ) );
174 ?>
175 </div>
176 <?php endif; ?>
177
178 <?php
179 ob_start();
180 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, null );
181 $custom_cols = ob_get_clean();
182 echo wp_kses_post( str_replace( array( '<td', '</td>' ), array( '<div', '</div>' ), $custom_cols ) );
183 ?>
184 </div>
185 <?php $tptTierRows[] = ob_get_clean(); ?>
186
187 <?php $iterator = new ArrayIterator( $pricing_rule->getRules() ); ?>
188
189 <?php while ( $iterator->valid() ) : ob_start(); ?>
190 <?php
191 $currentPrice = $iterator->current();
192 $currentQuantity = $iterator->key();
193
194 $iterator->next();
195
196 $discountAmount = $tierDiscounts[ $currentQuantity ];
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"
225 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
226 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
227 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
228 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>"
229 style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
230
231 <?php if ( $settings['quantity_column_title'] ) : ?>
232 <div>
233 <span class="tiered-pricing-table-row-qty"><?php echo esc_attr( $quantity ); ?></span>
234 <span class="tiered-pricing-table-row-qty-unit"> <?php echo esc_attr( $quantityUnit ); ?></span>
235 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $currentQuantity, 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-saving">
246 <span class="tiered-pricing-table-row-bar"><i style="width: <?php echo esc_attr( $maxDiscount > 0 ? min( 100, round( $discountAmount / $maxDiscount * 100 ) ) : 0 ); ?>%"></i></span>
247 <span class="tiered-pricing-table-row-discount"><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings ) ); ?></span>
248 </span>
249 <?php else : ?>
250 <span class="tiered-pricing-table-row-saving">
251 <span class="tiered-pricing-table-row-bar"><i style="width: 0"></i></span>
252 <span class="tiered-pricing-table-row-discount tiered-pricing-table-row-discount--empty">&mdash;</span>
253 </span>
254 <?php endif; ?>
255 </div>
256 <?php endif; ?>
257
258 <?php if ( $settings['price_column_title'] ) : ?>
259 <div class="tiered-pricing-table-row-price">
260 <?php echo wp_kses_post( wc_price( $pricing_rule->getTierPrice( $currentQuantity ) ) ); ?>
261 </div>
262 <?php endif; ?>
263
264 <?php
265 ob_start();
266 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, $currentQuantity );
267 $custom_cols = ob_get_clean();
268 echo wp_kses_post( str_replace( array( '<td', '</td>' ), array( '<div', '</div>' ), $custom_cols ) );
269 ?>
270 </div>
271 <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
272 <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
273 <?php do_action( 'tiered_pricing_table/tiered_pricing/rows', $pricing_rule, $settings, 'tiered-pricing-table-style-5' ); ?>
274 <?php do_action( 'tiered_pricing_table/table/tfoot', $pricing_rule, $settings, 'tiered-pricing-table-style-5' ); ?>
275 </div>
276 </div>
277
278 <?php do_action( 'tiered_pricing_table/tiered_pricing/after', $pricing_rule, $product_id ); ?>
279 </div>
280
281 <style>
282 <?php
283 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code() ) {
284 echo esc_attr( '#' . $id ) . ' .tiered-pricing-table-row { cursor: pointer; }';
285 }
286 ?>
287
288 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing--active {
289 background-color: <?php echo esc_attr( Settings::hex2rgba( $settings['active_tier_color'], 0.08 ) ); ?> !important;
290 border-left-color: <?php echo esc_attr( 'no' === ( $settings['active_tier_border'] ?? 'yes' ) ? 'transparent' : $settings['active_tier_color'] ); ?> !important;
291 }
292
293 <?php $barColor = ! empty( $settings['discount_badge_color'] ) ? $settings['discount_badge_color'] : $settings['active_tier_color']; ?>
294 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing-table-row-bar i {
295 background-color: <?php echo esc_attr( Settings::hex2rgba( $barColor, 0.45 ) ); ?>;
296 }
297
298 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing--active .tiered-pricing-table-row-bar i,
299 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing-table-row:hover .tiered-pricing-table-row-bar i {
300 background-color: <?php echo esc_attr( $barColor ); ?>;
301 }
302
303 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing-table-row-discount:not(.tiered-pricing-table-row-discount--empty) {
304 color: <?php echo esc_attr( $barColor ); ?>;
305 }
306
307 </style>
308 <?php endif; ?>
309