PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.1.0
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-horizontal-table.php

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

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