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

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

287 lines 12.0 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-1 <?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-discount"><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings ) ); ?></span>
157 <?php else : ?>
158 <span class="tiered-pricing-table-row-discount tiered-pricing-table-row-discount--empty">&mdash;</span>
159 <?php endif; ?>
160 </div>
161 <?php endif; ?>
162
163 <?php if ( $settings['price_column_title'] ) : ?>
164 <div class="tiered-pricing-table-row-price">
165 <?php
166 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ),
167 array( 'price' => $real_price ) ) ) );
168 ?>
169 </div>
170 <?php endif; ?>
171
172 <?php
173 ob_start();
174 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, null );
175 $custom_cols = ob_get_clean();
176 echo wp_kses_post( str_replace( array( '<td', '</td>' ), array( '<div', '</div>' ), $custom_cols ) );
177 ?>
178 </div>
179 <?php $tptTierRows[] = ob_get_clean(); ?>
180
181 <?php $iterator = new ArrayIterator( $pricing_rule->getRules() ); ?>
182
183 <?php while ( $iterator->valid() ) : ob_start(); ?>
184 <?php
185 $currentPrice = $iterator->current();
186 $currentQuantity = $iterator->key();
187
188 $iterator->next();
189
190 $discountAmount = $tierDiscounts[ $currentQuantity ];
191
192 $quantity = number_format_i18n( $currentQuantity );
193
194 if ( $iterator->valid() ) {
195
196 if ( intval( $iterator->key() - 1 != $currentQuantity ) && 'range' === $settings['quantity_type'] ) {
197 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
198 }
199
200 } else {
201 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
202 $currentQuantity, $pricing_rule, 'table' );
203 }
204
205 $quantityUnit = $settings['quantity_measurement_plural'];
206
207 $currentProductPrice = $pricing_rule->getTierPrice( $currentQuantity );
208
209 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
210 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
211 ) );
212
213 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
214 'price' => $pricing_rule->getTierPrice( $currentQuantity, false ),
215 ) );
216
217 ?>
218 <div class="tiered-pricing-table-row"
219 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
220 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
221 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
222 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>"
223 style="grid-template-columns: repeat(<?php echo (int) $columns; ?>, 1fr);">
224
225 <?php if ( $settings['quantity_column_title'] ) : ?>
226 <div>
227 <span class="tiered-pricing-table-row-qty"><?php echo esc_attr( $quantity ); ?></span>
228 <span class="tiered-pricing-table-row-qty-unit"> <?php echo esc_attr( $quantityUnit ); ?></span>
229 <?php do_action( 'tiered_pricing_table/table/label', $pricing_rule, $currentQuantity, array(
230 'id' => $id,
231 'style' => 'default',
232 ) ); ?>
233 </div>
234 <?php endif; ?>
235
236 <?php if ( $settings['discount_column_title'] ) : ?>
237 <div>
238 <?php if ( $discountAmount > 0 ) : ?>
239 <span class="tiered-pricing-table-row-discount"><?php echo wp_kses_post( PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings ) ); ?></span>
240 <?php else : ?>
241 <span class="tiered-pricing-table-row-discount tiered-pricing-table-row-discount--empty">&mdash;</span>
242 <?php endif; ?>
243 </div>
244 <?php endif; ?>
245
246 <?php if ( $settings['price_column_title'] ) : ?>
247 <div class="tiered-pricing-table-row-price">
248 <?php echo wp_kses_post( wc_price( $pricing_rule->getTierPrice( $currentQuantity ) ) ); ?>
249 </div>
250 <?php endif; ?>
251
252 <?php
253 ob_start();
254 do_action( 'tiered_pricing_table/tiered_pricing/row_columns', $pricing_rule, $currentQuantity );
255 $custom_cols = ob_get_clean();
256 echo wp_kses_post( str_replace( array( '<td', '</td>' ), array( '<div', '</div>' ), $custom_cols ) );
257 ?>
258 </div>
259 <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
260 <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
261 <?php do_action( 'tiered_pricing_table/tiered_pricing/rows', $pricing_rule, $settings, 'tiered-pricing-table-style-1' ); ?>
262 <?php do_action( 'tiered_pricing_table/table/tfoot', $pricing_rule, $settings, 'tiered-pricing-table-style-1' ); ?>
263 </div>
264 </div>
265
266 <?php do_action( 'tiered_pricing_table/tiered_pricing/after', $pricing_rule, $product_id ); ?>
267 </div>
268
269 <style>
270 <?php
271 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code() ) {
272 echo esc_attr( '#' . $id ) . ' .tiered-pricing-table-row { cursor: pointer; }';
273 }
274 ?>
275
276 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing--active {
277 background-color: <?php echo esc_attr( Settings::hex2rgba( $settings['active_tier_color'], 0.06 ) ); ?> !important;
278 border-left-color: <?php echo esc_attr( 'no' === ( $settings['active_tier_border'] ?? 'yes' ) ? 'transparent' : $settings['active_tier_color'] ); ?> !important;
279 }
280
281 <?php echo esc_attr( '#' . $id ); ?> .tiered-pricing-table-row-discount:not(.tiered-pricing-table-row-discount--empty) {
282 color: <?php echo esc_attr( $settings['active_tier_color'] ); ?>;
283 }
284
285 </style>
286 <?php endif; ?>
287