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

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

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