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-style-2.php

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

230 lines 8.3 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-2 <?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
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' => '2',
92 ) );
93 ?>
94
95 <div class="tiered-pricing-block__quantity">
96 <?php if ( 1 >= array_keys( $price_rules )[0] - $minimum || 'static' === $settings['quantity_type'] ) : ?>
97 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?></span>
98 <?php if ( $minimum > 1 ) : ?>
99 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
100 <?php else : ?>
101 <?php echo esc_html( $settings['quantity_measurement_singular'] ); ?>
102 <?php endif; ?>
103 <?php else : ?>
104 <span><?php echo esc_attr( number_format_i18n( $minimum ) ); ?> - <?php echo esc_attr( number_format_i18n( array_keys( $price_rules )[0] - 1 ) ); ?></span>
105 <?php echo esc_html( $settings['quantity_measurement_plural'] ); ?>
106 <?php endif; ?>
107 </div>
108
109 <div class="tiered-pricing-block__price">
110 <?php
111 echo wp_kses_post( wc_price( wc_get_price_to_display( wc_get_product( $product_id ), array(
112 'price' => $real_price,
113 ) ) ) );
114 ?>
115
116 <?php if ( $settings['show_discount_column'] ) : ?>
117 <?php
118 $discountAmount = 0;
119 if ( CalculationLogic::calculateDiscountBasedOnRegularPrice() && $product->is_on_sale() ) {
120 $discountAmount = PriceManager::calculateDiscount( $product->get_regular_price(),
121 $product->get_sale_price() );
122 }
123 ?>
124 <?php if ( $discountAmount > 0 ) : ?>
125 <span class="tiered-pricing-block__price-discount">
126 <?php
127 echo wp_kses_post( '(' . PricingTable::formatDiscount( $discountAmount, $pricing_rule, $product, null, $settings, 'off' ) . ')' );
128 ?>
129 </span>
130 <?php endif; ?>
131 <?php endif; ?>
132 </div>
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 <?php
185 do_action( 'tiered_pricing_table/blocks/label', $pricing_rule, $currentQuantity, array(
186 'id' => $id,
187 'style' => '2',
188 ) );
189 ?>
190 <div class="tiered-pricing-block__quantity"><?php echo esc_html( $quantity ); ?></div>
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 </div>
208 <?php $tptTierRows[] = ob_get_clean(); endwhile; ?>
209 <?php echo PricingTable::orderTiers( $tptTierRows, $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rows escaped when rendered above ?>
210
211 <?php do_action( 'tiered_pricing_table/blocks/blocks', $pricing_rule, $settings ); ?>
212 </div>
213
214 <?php do_action( 'tiered_pricing_table/blocks/after_blocks', $pricing_rule ); ?>
215 </div>
216
217 <style>
218 <?php
219 if ( $settings['clickable_rows'] && tpt_fs()->can_use_premium_code()) {
220 echo esc_attr('#' . $id) . ' .tiered-pricing-block {cursor: pointer; }';
221 }
222 ?>
223
224 <?php echo esc_attr('#' . $id); ?>
225 .tiered-pricing--active {
226 border-color: <?php echo esc_attr($settings['active_tier_color']); ?> !important;
227 }
228
229 </style>
230 <?php endif; ?>