PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.0
Tiered Pricing Table for WooCommerce v8.1.0
8.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 All 92 releases
tier-pricing-table / views / frontend / tiered-pricing-blocks-style-4.php

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

253 lines 9.0 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\PricingTable;
4 use TierPricingTable\PricingRule;
5 use TierPricingTable\Settings\Settings;
6
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10 /**
11 * Available variables
12 *
13 * @var array $price_rules
14 * @var PricingRule $pricing_rule
15 * @var string $real_price
16 * @var string $product_name
17 * @var string $pricing_type
18 * @var WC_Product $product
19 * @var string $id
20 * @var int $product_id
21 * @var int $minimum
22 * @var array $settings
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 ?>
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-4 <?php echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ) ? 'tiered-pricing-blocks--slim' : ''; ?>"
50
51 <?php echo PricingTable::layoutStyleAttribute( $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper ?>
52 id="<?php echo esc_attr( $id ); ?>"
53 data-product-id="<?php echo esc_attr( $product_id ); ?>"
54 data-price-rules="<?php echo esc_attr( htmlspecialchars( json_encode( $price_rules ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) ); ?>"
55 data-minimum="<?php echo esc_attr( $minimum ); ?>"
56 data-product-name="<?php echo esc_attr( $product_name ); ?>"
57 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
58 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
59 data-price="<?php echo esc_attr( $price ); ?>"
60 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
61 >
62 <?php $tptTierRows = array(); ob_start(); ?>
63 <div class="tiered-pricing-block tiered-pricing--active"
64 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
65 data-tiered-price="
66 <?php
67 echo esc_attr( wc_get_price_to_display( wc_get_product( $product_id ), array(
68 'price' => $real_price,
69 ) ) );
70 ?>
71 "
72 data-tiered-price-exclude-taxes="
73 <?php
74 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
75 'price' => $real_price,
76 ) ) );
77 ?>
78 "
79 data-tiered-price-include-taxes="
80 <?php
81 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
82 'price' => $real_price,
83 ) ) );
84 ?>
85 ">
86
87 <?php
88 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $minimum, array(
89 'id' => $id,
90 'style' => '4',
91 ) );
92 ?>
93 <div class="tiered-pricing-block__price">
94 <?php
95 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
96 'price' => $real_price,
97 ) ) ) );
98 ?>
99
100 <?php if ( $settings['show_discount_column'] ) : ?>
101 <?php
102 $discountAmount = 0;
103 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
104 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
105 $product->get_sale_price() );
106 }
107 ?>
108 <?php if ( $discountAmount > 0 ) : ?>
109 <span class="tiered-pricing-block__price-discount">
110 <?php
111 echo wp_kses_post( '(' . PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings, 'off' ) . ')' );
112 ?>
113 </span>
114 <?php endif; ?>
115 <?php endif; ?>
116 </div>
117
118 <div class="tiered-pricing-block__quantity">
119 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
120 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?></span>
121 <?php if ( $minimum > 1 ) : ?>
122 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
123 <?php else : ?>
124 <?php echo esc_html( $settings['quantity_measurement_singular'] ); ?>
125 <?php endif; ?>
126 <?php else : ?>
127 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $price_rules )[0] - 1 ) ); ?></span>
128 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
129 <?php endif; ?>
130 </div>
131
132 </div>
133 <?php $tptTierRows[] = ob_get_clean(); ?>
134
135 <?php $iterator = new ArrayIterator( $price_rules ); ?>
136
137 <?php while ( $iterator->valid() ) : ob_start(); ?>
138 <?php
139 $currentPrice = $iterator->current();
140 $currentQuantity = $iterator->key();
141
142 if ( 'percentage' === $pricing_type ) {
143 $discountAmount = $currentPrice;
144 } else {
145 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
146 $pricing_rule->getTierPrice( $currentQuantity, false ) );
147 }
148
149 $iterator->next();
150
151 if ( $iterator->valid() ) {
152 $quantity = number_format_i18n( $currentQuantity );
153
154 if ( (int) $iterator->key() - 1 !== (int) $currentQuantity && 'range' === $settings['quantity_type'] ) {
155 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
156 }
157 } else {
158 $quantity = number_format_i18n( $currentQuantity );
159
160 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
161 $currentQuantity, $pricing_rule, 'blocks' );
162 }
163
164 $quantity = $quantity . ' ' . $settings['quantity_measurement_plural'];
165
166 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
167
168 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
169 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
170 ) );
171
172 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
173 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
174 ) );
175
176 ?>
177
178 <div class="tiered-pricing-block"
179 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
180 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
181 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
182 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>">
183
184 <?php
185 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $currentQuantity, array(
186 'id' => $id,
187 'style' => '4',
188 ) );
189 ?>
190
191 <div class="tiered-pricing-block__price">
192 <span>
193 <?php
194 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity,
195 $product_id ) ) );
196 ?>
197 </span>
198
199 <?php if ( $settings['show_discount_column'] && $discountAmount > 0 ) : ?>
200 <span class="tiered-pricing-block__price-discount">
201 <?php
202 echo wp_kses_post( '(' . PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings, 'off' ) . ')' );
203 ?>
204 </span>
205 <?php endif; ?>
206 </div>
207
208 <div class="tiered-pricing-block__quantity"><?php echo esc_html( $quantity ); ?></div>
209
210 </div>
211 <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
212 <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
213
214 <?php do_action( 'tiered_pricing_table/blocks/blocks', $pricing_rule, $settings ); ?>
215 </div>
216
217 <?php do_action( 'tiered_pricing_table/blocks/after_blocks', $pricing_rule ); ?>
218 </div>
219
220 <style>
221 <?php
222 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
223 echo esc_attr('#' . $id) . ' .tiered-pricing-block {cursor: pointer; }';
224 }
225 ?>
226
227 <?php echo esc_attr('#' . $id); ?>
228 .tiered-pricing--active {
229 border-color: <?php echo esc_attr($settings['active_tier_color']); ?> !important;
230 }
231
232 .tiered-pricing-blocks--style-4 .tiered-pricing-block {
233 padding: 10px 15px;
234 border-color: <?php echo esc_html(Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.3 )); ?>;
235 }
236
237 .tiered-pricing-blocks--style-4 .tiered-pricing-block__quantity {
238 line-height: normal;
239 font-size: .8em;
240 margin-top: 5px;
241 }
242
243 .tiered-pricing-blocks--style-4 .tiered-pricing-block__price {
244 line-height: normal;
245 font-weight: 600;
246 }
247
248 .tiered-pricing-blocks--style-4 .tiered-pricing--active {
249 background: <?php echo esc_html(Settings::shadeHexWithOpacity( $settings['active_tier_color'], 0.08 )); ?>;
250 }
251
252 </style>
253 <?php endif; ?>