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

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

247 lines 8.9 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 $backgroundColor = Settings::hex2rgba( $settings['active_tier_color'], 0.8 );
42
43 ?>
44 <?php if ( ! empty( $price_rules ) ) : ?>
45
46 <div class="tiered-pricing-wrapper">
47 <?php if ( ! empty( $settings['title'] ) ) : ?>
48 <h3 style="clear:both; margin: 20px 0;"><?php echo esc_attr( $settings['title'] ); ?></h3>
49 <?php endif; ?>
50
51 <div class="tiered-pricing-blocks tiered-pricing-blocks--styled tiered-pricing-blocks--style-1 <?php echo ( isset( $settings['compact_layout'] ) && $settings['compact_layout'] === 'yes' ) ? 'tiered-pricing-blocks--slim' : ''; ?>"
52
53 <?php echo PricingTable::layoutStyleAttribute( $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the helper ?>
54 id="<?php echo esc_attr( $id ); ?>"
55 data-product-id="<?php echo esc_attr( $product_id ); ?>"
56 data-price-rules="<?php echo esc_attr( htmlspecialchars( json_encode( $price_rules ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) ); ?>"
57 data-minimum="<?php echo esc_attr( $minimum ); ?>"
58 data-product-name="<?php echo esc_attr( $product_name ); ?>"
59 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
60 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
61 data-price="<?php echo esc_attr( $price ); ?>"
62 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
63 >
64
65 <?php $tptTierRows = array(); ob_start(); ?>
66 <div class="tiered-pricing-block tiered-pricing--active"
67 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
68 data-tiered-price="
69 <?php
70 echo esc_attr( wc_get_price_to_display( wc_get_product( $product_id ), array(
71 'price' => $real_price,
72 ) ) );
73 ?>
74 "
75 data-tiered-price-exclude-taxes="
76 <?php
77 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
78 'price' => $real_price,
79 ) ) );
80 ?>
81 "
82 data-tiered-price-include-taxes="
83 <?php
84 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
85 'price' => $real_price,
86 ) ) );
87 ?>
88 ">
89
90 <?php
91 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $minimum, array(
92 'id' => $id,
93 'style' => '1',
94 ) );
95 ?>
96
97 <div class="tiered-pricing-block__quantity">
98 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
99 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?></span>
100 <?php if ( $minimum > 1 ) : ?>
101 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
102 <?php else : ?>
103 <?php echo esc_html( $settings['quantity_measurement_singular'] ); ?>
104 <?php endif; ?>
105 <?php else : ?>
106 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $price_rules )[0] - 1 ) ); ?></span>
107 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
108 <?php endif; ?>
109 </div>
110
111 <div class="tiered-pricing-block__price">
112 <?php
113 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
114 'price' => $real_price,
115 ) ) ) );
116 ?>
117
118 <?php if ( $settings['show_discount_column'] ) : ?>
119 <?php
120 $discountAmount = 0;
121 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
122 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
123 $product->get_sale_price() );
124 }
125 ?>
126 <?php if ( $discountAmount > 0 ) : ?>
127 <span class="tiered-pricing-block__price-discount">
128 <?php
129 echo wp_kses_post( '(' . PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings, 'off' ) . ')' );
130 ?>
131 </span>
132 <?php endif; ?>
133 <?php endif; ?>
134 </div>
135 </div>
136 <?php $tptTierRows[] = ob_get_clean(); ?>
137
138 <?php $iterator = new ArrayIterator( $price_rules ); ?>
139
140 <?php while ( $iterator->valid() ) : ob_start(); ?>
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 = number_format_i18n( $currentQuantity );
156
157 if ( (int) $iterator->key() - 1 !== (int) $currentQuantity && 'range' === $settings['quantity_type'] ) {
158 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
159 }
160 } else {
161 $quantity = number_format_i18n( $currentQuantity );
162
163 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
164 $currentQuantity, $pricing_rule, 'blocks' );
165 }
166
167 $quantity = $quantity . ' ' . $settings['quantity_measurement_plural'];
168
169 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
170
171 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
172 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
173 ) );
174
175 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
176 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
177 ) );
178
179 ?>
180
181 <div class="tiered-pricing-block"
182 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
183 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
184 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
185 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>">
186
187 <?php
188 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $currentQuantity, array(
189 'id' => $id,
190 'style' => '1',
191 ) ); ?>
192
193 <div class="tiered-pricing-block__quantity"><?php echo esc_html( $quantity ); ?></div>
194 <div class="tiered-pricing-block__price">
195 <span>
196 <?php
197 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity,
198 $product_id ) ) );
199 ?>
200 </span>
201
202 <?php if ( $settings['show_discount_column'] && $discountAmount > 0 ) : ?>
203 <span class="tiered-pricing-block__price-discount">
204 <?php
205 echo wp_kses_post( '(' . PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings, 'off' ) . ')' );
206 ?>
207 </span>
208 <?php endif; ?>
209 </div>
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 echo esc_attr('#' . $id); ?>
222 .tiered-pricing-block {
223 border-color: <?php echo esc_html($backgroundColor); ?>;
224 }
225
226 <?php echo esc_attr('#' . $id); ?>
227 .tiered-pricing-block .tiered-pricing-block__quantity {
228 background: <?php echo esc_html($backgroundColor); ?>;
229 }
230
231 <?php
232 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
233 echo esc_attr('#' . $id) . ' .tiered-pricing-block {cursor: pointer; }';
234 }
235 ?>
236
237 <?php echo esc_attr('#' . $id); ?>
238 .tiered-pricing--active {
239 border-color: <?php echo esc_attr($settings['active_tier_color']); ?> !important;
240 }
241
242 <?php echo esc_attr('#' . $id); ?>
243 .tiered-pricing--active .tiered-pricing-block__quantity {
244 background: <?php echo esc_html($settings['active_tier_color']); ?> !important;
245 }
246 </style>
247 <?php endif; ?>