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
← All changes | src/Addons/TierLabels/TierLabel.php +50 -21 6.1.0 → 8.0.2 View file →
@@ -15,8 +15,9 @@
15 15 private $paddingX;
16 16 private $paddingY;
17 17 private $borderRadius;
18 18 private $borderStyle;
19 + private $icon;
19 20
20 21 public function __construct( $id, $args = array() ) {
21 22 $args = wp_parse_args( $args, array(
22 23 'title' => '',
@@ -30,8 +31,9 @@
30 31 'padding_x' => 8,
31 32 'padding_y' => 2,
32 33 'border_radius' => 4,
33 34 'border_style' => 'solid',
35 + 'icon' => '',
34 36 ) );
35 37
36 38 $this->id = $id;
37 39 $this->title = $args['title'];
@@ -39,14 +41,15 @@
39 41 $this->textColor = $args['text_color'];
40 42 $this->borderColor = $args['border_color'];
41 43 $this->style = $args['style'];
42 44 $this->CSSClass = $args['css_class'];
43 - $this->fontSize = intval( $args['font_size'] );
44 - $this->borderWidth = intval( $args['border_width'] );
45 - $this->paddingX = intval( $args['padding_x'] );
46 - $this->paddingY = intval( $args['padding_y'] );
47 - $this->borderRadius = intval( $args['border_radius'] );
48 - $this->borderStyle = $args['border_style'];
45 + $this->fontSize = isset($args['font_size']) ? (int) $args['font_size'] : 12;
46 + $this->borderWidth = isset($args['border_width']) ? (int) $args['border_width'] : 0;
47 + $this->paddingX = isset($args['padding_x']) ? (int) $args['padding_x'] : 8;
48 + $this->paddingY = isset($args['padding_y']) ? (int) $args['padding_y'] : 2;
49 + $this->borderRadius = isset($args['border_radius']) ? (int) $args['border_radius'] : 4;
50 + $this->borderStyle = $args['border_style'] ?? 'solid';
51 + $this->icon = $args['icon'] ?? '';
49 52 }
50 53
51 54 public function getId() {
52 55 return $this->id;
@@ -91,12 +94,16 @@
91 94 public function getBorderRadius() {
92 95 return $this->borderRadius;
93 96 }
94 97
95 - public function getBorderStyle() {
98 + public function getBorderStyle(): string {
96 99 return $this->borderStyle;
97 100 }
98 101
102 + public function getIcon(): string {
103 + return $this->icon;
104 + }
105 +
99 106 public function getCSSClass(): ?string {
100 107 return $this->CSSClass;
101 108 }
102 109
@@ -101,21 +108,22 @@
101 108 }
102 109
103 110 public function toArray(): array {
104 111 return array(
105 - 'id' => $this->getId(),
106 - 'title' => $this->getTitle(),
107 - 'background_color' => $this->getBackgroundColor(),
108 - 'text_color' => $this->getTextColor(),
109 - 'border_color' => $this->getBorderColor(),
110 - 'style' => $this->getStyle(),
111 - 'css_class' => $this->getCSSClass(),
112 - 'font_size' => $this->getFontSize(),
113 - 'border_width' => $this->getBorderWidth(),
114 - 'padding_x' => $this->getPaddingX(),
115 - 'padding_y' => $this->getPaddingY(),
116 - 'border_radius' => $this->getBorderRadius(),
117 - 'border_style' => $this->getBorderStyle(),
112 + 'id' => $this->id,
113 + 'title' => $this->title,
114 + 'background_color' => $this->backgroundColor,
115 + 'text_color' => $this->textColor,
116 + 'border_color' => $this->borderColor,
117 + 'style' => $this->style,
118 + 'css_class' => $this->CSSClass,
119 + 'font_size' => $this->fontSize,
120 + 'border_width' => $this->borderWidth,
121 + 'padding_x' => $this->paddingX,
122 + 'padding_y' => $this->paddingY,
123 + 'border_radius' => $this->borderRadius,
124 + 'border_style' => $this->borderStyle,
125 + 'icon' => $this->icon,
118 126 );
119 127 }
120 128
121 129 public function isValid(): bool {
@@ -166,10 +174,31 @@
166 174 $style .= 'border: ' . esc_attr( $borderWidth ) . 'px solid ' . esc_attr( $borderColor ?: '#000000' ) . ';';
167 175 }
168 176
169 177 $cssClass = $this->getCSSClass() ? ' ' . esc_attr( $this->getCSSClass() ) : '';
178 +
179 + $iconSvg = '';
180 + if ( $this->getIcon() ) {
181 + $iconSvg = $this->getIconSvg( $this->getIcon() );
182 + // Adjust layout for icon + text
183 + $style .= 'display: inline-flex; align-items: center; justify-content: center; gap: 2px;';
184 + }
170 185
171 - $labelHTML = '<span id="' . esc_attr( $this->getId() ) . '" class="tiered-pricing-tier-label' . $cssClass . '" style="' . $style . '">' . esc_html( $this->getTitle() ) . '</span>';
186 + $labelHTML = '<span id="' . esc_attr( $this->getId() ) . '" class="tiered-pricing-tier-label' . $cssClass . '" style="' . $style . '">' . $iconSvg . esc_html( $this->getTitle() ) . '</span>';
172 187
173 188 return apply_filters( 'tiered_pricing_table/addons/tier_labels/label_html', $labelHTML, $this );
189 + }
190 +
191 + private function getIconSvg( string $iconName ): string {
192 + $icons = array(
193 + 'star' => '<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>',
194 + 'fire' => '<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z"></path></svg>',
195 + 'lightning' => '<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon></svg>',
196 + 'tag' => '<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z"></path><line x1="7" y1="7" x2="7.01" y2="7"></line></svg>',
197 + 'crown' => '<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 4 3 12h14l3-12-6 7-4-7-4 7-6-7zm3 16h14"></path></svg>',
198 + 'percent' => '<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="5" x2="5" y2="19"></line><circle cx="6.5" cy="6.5" r="2.5"></circle><circle cx="17.5" cy="17.5" r="2.5"></circle></svg>',
199 + 'award' => '<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="8" r="7"></circle><polyline points="8.21 13.89 7 23 12 20 17 23 15.79 13.88"></polyline></svg>',
200 + );
201 +
202 + return $icons[$iconName] ?? '';
174 203 }
175 204 }