PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.4
Tiered Pricing Table for WooCommerce v7.1.4
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 7.1.4, at views/frontend/tiered-pricing-table-style-1.php

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