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

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

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