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 / src / Addons / GlobalTieredPricing / CPT / Columns / Pricing.php

Pricing.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/GlobalTieredPricing/CPT/Columns/Pricing.php

141 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\GlobalTieredPricing\CPT\Columns;
2
3 use ArrayIterator;
4 use Exception;
5 use TierPricingTable\Addons\GlobalTieredPricing\GlobalPricingRule;
6 use TierPricingTable\Core\ServiceContainerTrait;
7
8 class Pricing {
9
10 use ServiceContainerTrait;
11
12 public function getName(): string {
13 return __( 'Pricing', 'tier-pricing-table' );
14 }
15
16 public function render( GlobalPricingRule $rule ) {
17 try {
18 $rule->validatePricing();
19
20 $pricingType = $rule->getTieredPricingType();
21 $rules = 'percentage' === $pricingType ? $rule->getPercentageTieredPricingRules() : $rule->getFixedTieredPricingRules();
22 $minimum = $rule->getMinimum() ? intval( $rule->getMinimum() ) : 1;
23
24 $regularProductPriceString = __( 'Regular price', 'tier-pricing-table' );
25
26 if ( $rule->getPricingType() === 'flat' ) {
27 if ( $rule->getSalePrice() ) {
28 $regularProductPriceString = wc_price( $rule->getSalePrice() );
29 } elseif ( $rule->getRegularPrice() ) {
30 $regularProductPriceString = wc_price( $rule->getRegularPrice() );
31 }
32 } elseif ( $rule->getDiscount() ) {
33 $regularProductPriceString = $rule->getDiscount() . '% off';
34 }
35
36 ?>
37
38 <?php
39 $applyingType = $rule->getApplyingType() === 'individual' ? __( '(Individual)', 'tier-pricing-table' ) : __( '(Mix and match)', 'tier-pricing-table' );
40 ?>
41 <div style="margin-bottom: 12px;">
42 <?php
43 $hasBasePricing = ( $rule->getPricingType() === 'flat' && ( $rule->getRegularPrice() || $rule->getSalePrice() ) ) || ( $rule->getPricingType() !== 'flat' && $rule->getDiscount() );
44 if ( $hasBasePricing ) : ?>
45 <div style="margin-bottom: 8px;">
46 <strong style="display: block; margin-bottom: 4px;"><?php esc_html_e( 'Base Pricing:', 'tier-pricing-table' ); ?></strong>
47 <div style="display: flex; flex-wrap: wrap; gap: 4px;">
48 <?php if ( $rule->getPricingType() === 'flat' ) : ?>
49 <?php if ( $rule->getRegularPrice() ) : ?>
50 <span style="display: inline-block; padding: 2px 8px; background: #f0f0f1; border-radius: 3px; font-size: 12px; color: #3c434a; border: 1px solid #dcdcdc;">
51 <?php echo wp_kses_post( __( 'Regular:', 'tier-pricing-table' ) . ' <b>' . wc_price( $rule->getRegularPrice() ) . '</b>' ); ?>
52 </span>
53 <?php endif; ?>
54 <?php if ( $rule->getSalePrice() ) : ?>
55 <span style="display: inline-block; padding: 2px 8px; background: #f0f0f1; border-radius: 3px; font-size: 12px; color: #3c434a; border: 1px solid #dcdcdc;">
56 <?php echo wp_kses_post( __( 'Sale:', 'tier-pricing-table' ) . ' <b>' . wc_price( $rule->getSalePrice() ) . '</b>' ); ?>
57 </span>
58 <?php endif; ?>
59 <?php else : ?>
60 <?php if ( $rule->getDiscount() ) : ?>
61 <span style="display: inline-block; padding: 2px 8px; background: #f0f0f1; border-radius: 3px; font-size: 12px; color: #3c434a; border: 1px solid #dcdcdc;">
62 <?php esc_html_e( 'Discount:', 'tier-pricing-table' ); ?> <b><?php echo esc_html( $rule->getDiscount() ); ?>%</b>
63 (<?php echo $rule->getDiscountType() === 'sale_price' ? esc_html__( 'Sale price', 'tier-pricing-table' ) : esc_html__( 'Regular price', 'tier-pricing-table' ); ?>)
64 </span>
65 <?php endif; ?>
66 <?php endif; ?>
67 </div>
68 </div>
69 <?php endif; ?>
70
71 <?php if ( ! empty( $rules ) ) : ?>
72 <div>
73 <div style="display: flex; align-items: center; margin-bottom: 8px;">
74 <strong style="display: block; color: #1d2327; margin-right: 6px;"><?php esc_html_e( 'Tiered Rules:', 'tier-pricing-table' ); ?></strong>
75 <span style="color: #50575e; font-size: 13px;">
76 <?php echo esc_html( $applyingType ); ?>
77 </span>
78 </div>
79 <table style="width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; margin-bottom: 8px; border: 1px solid #c3c4c7; border-radius: 4px; overflow: hidden; background: #fff;">
80 <thead style="background: #f0f0f1; border-bottom: 2px solid #c3c4c7;">
81 <tr>
82 <th style="padding: 8px 10px; font-weight: 600; color: #1d2327;"><?php esc_html_e( 'Quantity', 'tier-pricing-table' ); ?></th>
83 <th style="padding: 8px 10px; font-weight: 600; color: #1d2327;"><?php echo 'percentage' === $pricingType ? esc_html__( 'Discount', 'tier-pricing-table' ) : esc_html__( 'Price', 'tier-pricing-table' ); ?></th>
84 </tr>
85 </thead>
86 <tbody>
87 <?php
88 // Base quantity row
89 $baseQtyStr = '';
90 if ( 1 >= array_keys( $rules )[0] - $minimum ) {
91 $baseQtyStr = number_format_i18n( $minimum );
92 } else {
93 $baseQtyStr = number_format_i18n( $minimum ) . ' - ' . number_format_i18n( array_keys( $rules )[0] - 1 );
94 }
95 ?>
96 <tr style="border-bottom: 1px solid #c3c4c7;">
97 <td style="padding: 6px 10px; color: #1d2327; border-right: 1px solid #e2e4e7;"><?php echo esc_html( $baseQtyStr ); ?></td>
98 <td style="padding: 6px 10px; color: #1d2327;"><?php echo wp_kses_post( $regularProductPriceString ); ?></td>
99 </tr>
100
101 <?php
102 $iterator = new ArrayIterator( $rules );
103 while ( $iterator->valid() ) {
104 $currentPrice = $iterator->current();
105 $currentQuantity = $iterator->key();
106 $iterator->next();
107
108 if ( $iterator->valid() ) {
109 $quantity = $currentQuantity;
110 if ( intval( $iterator->key() - 1 != $currentQuantity ) ) {
111 $quantity = number_format_i18n( $quantity );
112 if ( $this->getContainer()->getSettings()->get( 'quantity_type', 'range' ) === 'range' ) {
113 $quantity .= ' - ' . number_format_i18n( intval( $iterator->key() - 1 ) );
114 }
115 }
116 } else {
117 $quantity = number_format_i18n( $currentQuantity ) . '+';
118 }
119
120 $priceStr = 'percentage' === $pricingType ? esc_html( $currentPrice . '%' ) : wp_kses_post( wc_price( $currentPrice ) );
121 ?>
122 <tr style="border-bottom: 1px solid #c3c4c7;">
123 <td style="padding: 6px 10px; color: #1d2327; font-weight: 600; border-right: 1px solid #e2e4e7;"><?php echo esc_html( $quantity ); ?></td>
124 <td style="padding: 6px 10px; color: #0070bc; font-weight: 600;"><?php echo $priceStr; ?></td>
125 </tr>
126 <?php
127 }
128 ?>
129 </tbody>
130 </table>
131 </div>
132 <?php endif; ?>
133 </div>
134 <?php
135
136 } catch ( Exception $e ) {
137 echo wp_kses_post( '<div class="help_tip tpt-rule-status tpt-rule-status--invalid" data-tip="' . $e->getMessage() . '">!</div>' );
138 }
139 }
140 }
141