PluginProbe
Tiered Pricing Table for WooCommerce / 6.4.0
Tiered Pricing Table for WooCommerce v6.4.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-blocks-style-2.php

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

233 lines 7.7 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 <?php if ( ! empty( $price_rules ) ) : ?>
42
43 <div class="tiered-pricing-wrapper">
44 <?php if ( ! empty( $settings['title'] ) ) : ?>
45 <h3 style="clear:both; margin: 20px 0;"><?php echo esc_attr( $settings['title'] ); ?></h3>
46 <?php endif; ?>
47
48 <div class="tiered-pricing-blocks tiered-pricing-blocks--styled tiered-pricing-blocks--style-2"
49 id="<?php echo esc_attr( $id ); ?>"
50 data-product-id="<?php echo esc_attr( $product_id ); ?>"
51 data-price-rules="<?php echo esc_attr( htmlspecialchars( json_encode( $price_rules ) ) ); ?>"
52 data-minimum="<?php echo esc_attr( $minimum ); ?>"
53 data-product-name="<?php echo esc_attr( $product_name ); ?>"
54 data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
55 data-sale-price="<?php echo esc_attr( $sale_price ); ?>"
56 data-price="<?php echo esc_attr( $price ); ?>"
57 data-product-price-suffix="<?php echo esc_attr( $product->get_price_suffix() ); ?>"
58 >
59
60 <div class="tiered-pricing-block tiered-pricing--active"
61 data-tiered-quantity="<?php echo esc_attr( $minimum ); ?>"
62 data-tiered-price="
63 <?php
64 echo esc_attr( wc_get_price_to_display( wc_get_product( $product_id ), array(
65 'price' => $real_price,
66 ) ) );
67 ?>
68 "
69 data-tiered-price-exclude-taxes="
70 <?php
71 echo esc_attr( wc_get_price_excluding_tax( wc_get_product( $product_id ), array(
72 'price' => $real_price,
73 ) ) );
74 ?>
75 "
76 data-tiered-price-include-taxes="
77 <?php
78 echo esc_attr( wc_get_price_including_tax( wc_get_product( $product_id ), array(
79 'price' => $real_price,
80 ) ) );
81 ?>
82 ">
83
84 <?php
85 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $minimum, array(
86 'id' => $id,
87 'style' => '2',
88 ) );
89 ?>
90
91 <div class="tiered-pricing-block__quantity">
92 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
93 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?></span>
94 <?php if ( $minimum > 1 ) : ?>
95 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
96 <?php else : ?>
97 <?php echo esc_html( $settings['quantity_measurement_singular'] ); ?>
98 <?php endif; ?>
99 <?php else : ?>
100 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $price_rules )[0] - 1 ) ); ?></span>
101 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
102 <?php endif; ?>
103 </div>
104
105 <div class="tiered-pricing-block__price">
106 <?php
107 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
108 'price' => $real_price,
109 ) ) ) );
110 ?>
111
112 <?php if ( $settings['show_discount_column'] ) : ?>
113 <?php
114 $discountAmount = 0;
115 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
116 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
117 $product->get_sale_price() );
118 }
119 ?>
120 <?php if ( $discountAmount > 0 ) : ?>
121 <span class="tiered-pricing-block__price-discount">
122 <?php
123 // translators: %d: discount amount
124 echo esc_html( sprintf( __( '(%d%% off)', 'tier-pricing-table' ),
125 round( $discountAmount, 2 ) ) );
126 ?>
127 </span>
128 <?php endif; ?>
129 <?php endif; ?>
130 </div>
131 </div>
132
133 <?php $iterator = new ArrayIterator( $price_rules ); ?>
134
135 <?php while ( $iterator->valid() ) : ?>
136 <?php
137 $currentPrice = $iterator->current();
138 $currentQuantity = $iterator->key();
139
140 if ( 'percentage' === $pricing_type ) {
141 $discountAmount = $currentPrice;
142 } else {
143 $discountAmount = PriceManager::calculateDiscount( CalculationLogic::calculateDiscountBasedOnRegularPrice() ? $product->get_regular_price() : $product->get_price(),
144 $pricing_rule->getTierPrice( $currentQuantity, false ) );
145 }
146
147 $iterator->next();
148
149 if ( $iterator->valid() ) {
150 $quantity = $currentQuantity;
151
152 if ( intval( $iterator->key() - 1 != $currentQuantity ) ) {
153
154 $quantity = number_format_i18n( $quantity );
155
156 if ( 'range' === $settings['quantity_type'] ) {
157 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
158 }
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 <?php
187 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $currentQuantity, array(
188 'id' => $id,
189 'style' => '2',
190 ) );
191 ?>
192 <div class="tiered-pricing-block__quantity"><?php echo esc_html( $quantity ); ?></div>
193 <div class="tiered-pricing-block__price">
194 <span>
195 <?php
196 echo wp_kses_post( wc_price( PriceManager::getPriceByRules( $currentQuantity,
197 $product_id ) ) );
198 ?>
199 </span>
200
201 <?php if ( $settings['show_discount_column'] ) : ?>
202 <span class="tiered-pricing-block__price-discount">
203 <?php
204 // translators: %d: discount amount
205 echo esc_html( sprintf( __( '(%d%% off)', 'tier-pricing-table' ),
206 round( $discountAmount, 2 ) ) );
207 ?>
208 </span>
209 <?php endif; ?>
210 </div>
211 </div>
212 <?php endwhile; ?>
213
214 <?php do_action( 'tiered_pricing_table/blocks/blocks', $pricing_rule ); ?>
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 </style>
233 <?php endif; ?>