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-blocks-style-3.php

tiered-pricing-blocks-style-3.php in Tiered Pricing Table for WooCommerce 7.1.4, at views/frontend/tiered-pricing-blocks-style-3.php

281 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php use TierPricingTable\CalculationLogic;
2 use TierPricingTable\PriceManager;
3 use TierPricingTable\PricingRule;
4 use TierPricingTable\Settings\Settings;
5
6 if ( ! defined( 'WPINC' ) ) {
7 die;
8 }
9 /**
10 * Available variables
11 *
12 * @var array $price_rules
13 * @var PricingRule $pricing_rule
14 * @var string $real_price
15 * @var string $product_name
16 * @var string $pricing_type
17 * @var WC_Product $product
18 * @var string $id
19 * @var int $product_id
20 * @var int $minimum
21 * @var array $settings
22 */
23
24 $sale_price = $product->get_sale_price();
25
26 if ( $sale_price ) {
27 $sale_price = wc_get_price_to_display( $product, array(
28 'price' => $sale_price,
29 ) );
30 }
31
32 $regular_price = wc_get_price_to_display( $product, array(
33 'price' => $product->get_regular_price(),
34 ) );
35
36 $price = wc_get_price_to_display( $product, array(
37 'price' => $product->get_price(),
38 ) );
39
40 ?>
41
42 <?php if ( ! empty( $price_rules ) ) : ?>
43
44 <div class="tiered-pricing-wrapper">
45 <?php if ( ! empty( $settings['title'] ) ) : ?>
46 <h3 style="clear:both; margin: 20px 0;"><?php echo esc_attr( $settings['title'] ); ?></h3>
47 <?php endif; ?>
48
49 <div class="tiered-pricing-blocks tiered-pricing-blocks--styled tiered-pricing-blocks--style-3 <?php echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ) ? 'tiered-pricing-blocks--slim' : ''; ?>"
50 id="<?php echo esc_attr( $id ); ?>"
51 data-product-id="<?php echo esc_attr( $product_id ); ?>"
52 data-price-rules="<?php echo esc_attr( htmlspecialchars( json_encode( $price_rules ) ) ); ?>"
53 data-minimum="<?php echo esc_attr( $minimum ); ?>"
54 data-product-name="<?php echo esc_attr( $product_name ); ?>"
55 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
56 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
57 data-price="<?php echo esc_attr( $price ); ?>"
58 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
59 >
60
61 <div class="tiered-pricing-block tiered-pricing--active"
62 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
63 data-tiered-price="
64 <?php
65 echo esc_attr( wc_get_price_to_display( wc_get_product( $product_id ), array(
66 'price' => $real_price,
67 ) ) );
68 ?>
69 "
70 data-tiered-price-exclude-taxes="
71 <?php
72 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
73 'price' => $real_price,
74 ) ) );
75 ?>
76 "
77 data-tiered-price-include-taxes="
78 <?php
79 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
80 'price' => $real_price,
81 ) ) );
82 ?>
83 ">
84
85 <?php if ( $settings['show_discount_column'] ) : ?>
86 <?php
87 $discountAmount = 0;
88 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
89 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
90 $product->get_sale_price() );
91 }
92 ?>
93 <?php if ( $discountAmount > 0 ) : ?>
94 <div class="tiered-pricing-block__discount">
95 <span class="tiered-pricing-block__price-discount">
96 <?php
97 // translators: %d: discount amount
98 echo esc_html( sprintf( __( '%d%% off', 'tier-pricing-table' ),
99 round( $discountAmount, 2 ) ) );
100 ?>
101 </span>
102 </div>
103 <?php endif; ?>
104 <?php endif; ?>
105 <div class="tiered-pricing-block-inner">
106
107 <?php
108 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $minimum, array(
109 'id' => $id,
110 'style' => '3',
111 ) );
112 ?>
113
114 <div class="tiered-pricing-block__price">
115 <?php
116 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
117 'price' => $real_price,
118 ) ) ) );
119 ?>
120 </div>
121 <div class="tiered-pricing-block__quantity">
122 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
123 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?></span>
124 <?php if ( $minimum > 1 ) : ?>
125 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
126 <?php else : ?>
127 <?php echo esc_html( $settings['quantity_measurement_singular'] ); ?>
128 <?php endif; ?>
129 <?php else : ?>
130 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $price_rules )[0] - 1 ) ); ?></span>
131 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
132 <?php endif; ?>
133 </div>
134
135 </div>
136 </div>
137
138 <?php $iterator = new ArrayIterator( $price_rules ); ?>
139
140 <?php while ( $iterator->valid() ) : ?>
141 <?php
142 $currentPrice = $iterator->current();
143 $currentQuantity = $iterator->key();
144
145 if ( 'percentage' === $pricing_type ) {
146 $discountAmount = $currentPrice;
147 } else {
148 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
149 $pricing_rule->getTierPrice( $currentQuantity, false ) );
150 }
151
152 $iterator->next();
153
154 if ( $iterator->valid() ) {
155 $quantity = $currentQuantity;
156
157 if ( intval( $iterator->key() - 1 != $currentQuantity ) ) {
158
159 $quantity = number_format_i18n( $quantity );
160
161 if ( 'range' === $settings['quantity_type'] ) {
162 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
163 }
164 }
165 } else {
166 $quantity = number_format_i18n( $currentQuantity );
167
168 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
169 $currentQuantity, $pricing_rule, 'blocks' );
170 }
171
172 $quantity = $quantity . ' ' . $settings['quantity_measurement_plural'];
173
174 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
175
176 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
177 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
178 ) );
179
180 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
181 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
182 ) );
183
184 ?>
185
186 <div class="tiered-pricing-block"
187 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
188 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
189 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
190 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>">
191
192 <?php if ( $settings['show_discount_column'] ) : ?>
193 <div class="tiered-pricing-block__discount">
194
195 <span class="tiered-pricing-block__price-discount">
196 <?php
197 // translators: %d: discount amount
198 echo esc_html( sprintf( __( '%d%% off', 'tier-pricing-table' ),
199 round( $discountAmount, 2 ) ) );
200 ?>
201 </span>
202 </div>
203 <?php endif; ?>
204
205 <div class="tiered-pricing-block-inner">
206
207 <?php
208 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $currentQuantity, array(
209 'id' => $id,
210 'style' => '3',
211 ) );
212 ?>
213
214 <div class="tiered-pricing-block__price">
215 <span>
216 <?php
217 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity,
218 $product_id ) ) );
219 ?>
220 </span>
221 </div>
222 <div class="tiered-pricing-block__quantity"><?php echo esc_html( $quantity ); ?></div>
223 </div>
224
225 </div>
226 <?php endwhile; ?>
227
228 <?php do_action( 'tiered_pricing_table/blocks/blocks', $pricing_rule, $settings ); ?>
229 </div>
230
231 <?php do_action( 'tiered_pricing_table/blocks/after_blocks', $pricing_rule ); ?>
232 </div>
233
234 <style>
235 <?php
236 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
237 echo esc_attr('#' . $id) . ' .tiered-pricing-block {cursor: pointer; }';
238 }
239 ?>
240
241 <?php echo esc_attr('#' . $id); ?>
242 .tiered-pricing--active {
243 border-color: <?php echo esc_attr($settings['active_tier_color']); ?> !important;
244 }
245
246 .tiered-pricing-blocks--style-3 .tiered-pricing-block {
247 border-color: <?php echo esc_html(Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.3 )); ?>;
248 }
249
250 .tiered-pricing-blocks--style-3 .tiered-pricing-block__quantity {
251 line-height: normal;
252 font-size: .8em;
253 }
254
255 .tiered-pricing-blocks--style-3 .tiered-pricing-block__price {
256 line-height: normal;
257 font-weight: 600;
258 }
259
260 .tiered-pricing-blocks--style-3 .tiered-pricing-block__discount {
261 position: absolute;
262 background: <?php echo esc_html(Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.85 )); ?>;
263 color: #fff;
264 top: 0;
265 left: 50%;
266 translate: -50% -50%;
267 font-weight: 600;
268 padding: 0 8px;
269 white-space: nowrap;
270 border-radius: 3px;
271 display: flex;
272 align-items: center;
273 justify-content: center;
274 }
275
276 .tiered-pricing-blocks--style-3 .tiered-pricing--active .tiered-pricing-block__discount {
277 background: <?php echo esc_html( $settings['active_tier_color']); ?>;
278 }
279
280 </style>
281 <?php endif; ?>