PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
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.php

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

231 lines 8.2 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
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 <?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 ) ); ?>"
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
63 <?php $tptTierRows = array(); ob_start(); ?>
64 <div class="tiered-pricing-block tiered-pricing--active"
65 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
66 data-tiered-price="
67 <?php
68 echo esc_attr( wc_get_price_to_display( wc_get_product( $product_id ), array(
69 'price' => $real_price,
70 ) ) );
71 ?>
72 "
73 data-tiered-price-exclude-taxes="
74 <?php
75 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
76 'price' => $real_price,
77 ) ) );
78 ?>
79 "
80 data-tiered-price-include-taxes="
81 <?php
82 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
83 'price' => $real_price,
84 ) ) );
85 ?>
86 ">
87
88 <?php
89 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $minimum, array(
90 'id' => $id,
91 'style' => 'default',
92 ) );
93 ?>
94
95 <div class="tiered-pricing-block__price">
96 <?php
97 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
98 'price' => $real_price,
99 ) ) ) );
100 ?>
101
102 <?php if ( $settings['show_discount_column'] ) : ?>
103 <?php
104 $discountAmount = 0;
105 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
106 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
107 $product->get_sale_price() );
108 }
109 ?>
110 <?php if ( $discountAmount > 0 ) : ?>
111 <span class="tiered-pricing-block__price-discount">
112 <?php
113 echo wp_kses_post( '(' . PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings, 'off' ) . ')' );
114 ?>
115 </span>
116 <?php endif; ?>
117 <?php endif; ?>
118 </div>
119
120 <span class="tiered-pricing-block__quantity">
121 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
122 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?></span>
123 <?php if ( $minimum > 1 ) : ?>
124 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
125 <?php else : ?>
126 <?php echo esc_html( $settings['quantity_measurement_singular'] ); ?>
127 <?php endif; ?>
128 <?php else : ?>
129 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $price_rules )[0] - 1 ) ); ?></span>
130 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
131 <?php endif; ?>
132 </span>
133 </div>
134 <?php $tptTierRows[] = ob_get_clean(); ?>
135
136 <?php $iterator = new ArrayIterator( $price_rules ); ?>
137
138 <?php while ( $iterator->valid() ) : ob_start(); ?>
139 <?php
140 $currentPrice = $iterator->current();
141 $currentQuantity = $iterator->key();
142
143 if ( 'percentage' === $pricing_type ) {
144 $discountAmount = $currentPrice;
145 } else {
146 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
147 $pricing_rule->getTierPrice( $currentQuantity, false ) );
148 }
149
150 $iterator->next();
151
152 if ( $iterator->valid() ) {
153 $quantity = number_format_i18n( $currentQuantity );
154
155 if ( (int) $iterator->key() - 1 !== (int) $currentQuantity && 'range' === $settings['quantity_type'] ) {
156 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
157 }
158 } else {
159 $quantity = number_format_i18n( $currentQuantity );
160
161 $quantity .= apply_filters( 'tiered_pricing_table/tiered_pricing/last_tier_postfix', '+',
162 $currentQuantity, $pricing_rule, 'blocks' );
163 }
164
165 $quantity = $quantity . ' ' . $settings['quantity_measurement_plural'];
166
167 $currentProductPrice = PriceManager::getPriceByRules( $currentQuantity, $product_id );
168
169 $currentProductPriceExcludeTaxes = wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
170 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
171 ) );
172
173 $currentProductPriceIncludeTaxes = wc_get_price_including_tax( wc_get_product( $product_id ), array(
174 'price' => PriceManager::getPriceByRules( $currentQuantity, $product_id, null, null, false ),
175 ) );
176
177 ?>
178
179 <div class="tiered-pricing-block"
180 data-tiered-quantity="<?php echo esc_attr( $currentQuantity ); ?>"
181 data-tiered-price="<?php echo esc_attr( $currentProductPrice ); ?>"
182 data-tiered-price-exclude-taxes="<?php echo esc_attr( $currentProductPriceExcludeTaxes ); ?>"
183 data-tiered-price-include-taxes="<?php echo esc_attr( $currentProductPriceIncludeTaxes ); ?>">
184
185 <?php
186 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $currentQuantity, array(
187 'id' => $id,
188 'style' => 'default',
189 ) );
190 ?>
191
192 <div class="tiered-pricing-block__price">
193 <span>
194 <?php
195 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity,
196 $product_id ) ) );
197 ?>
198 </span>
199
200 <?php if ( $settings['show_discount_column'] && $discountAmount > 0 ) : ?>
201 <span class="tiered-pricing-block__price-discount">
202 <?php
203 echo wp_kses_post( '(' . PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, $currentQuantity, $settings, 'off' ) . ')' );
204 ?>
205 </span>
206 <?php endif; ?>
207 </div>
208 <span class="tiered-pricing-block__quantity"><?php echo esc_html( $quantity ); ?></span>
209 </div>
210 <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
211 <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
212
213 <?php do_action( 'tiered_pricing_table/blocks/blocks', $pricing_rule, $settings ); ?>
214 </div>
215
216 <?php do_action( 'tiered_pricing_table/blocks/after_blocks', $pricing_rule ); ?>
217 </div>
218
219 <style>
220 <?php
221 if ( $settings['clickable_rows']) {
222 echo esc_attr('#' . $id) . ' .tiered-pricing-block {cursor: pointer; }';
223 }
224 ?>
225
226 <?php echo esc_attr('#' . $id); ?>
227 .tiered-pricing--active {
228 border-color: <?php echo esc_attr($settings['active_tier_color']); ?> !important;
229 }
230 </style>
231 <?php endif; ?>