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

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