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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-product-attribute.php
woocommerce / includes Last commit date
abstracts 1 month ago admin 6 days ago blocks 11 months ago cli 1 month ago customizer 4 months ago data-stores 1 month ago emails 5 days ago export 1 year ago gateways 1 month ago import 3 months ago integrations 2 months ago interfaces 4 months ago legacy 4 months ago libraries 1 month ago log-handlers 1 year ago payment-tokens 5 years ago product-usage 1 year ago queue 4 months ago react-admin 1 month ago rest-api 1 month ago shipping 3 months ago shortcodes 1 month ago theme-support 2 years ago tracks 1 month ago traits 5 years ago walkers 5 years ago wccom-site 1 month ago widgets 2 months ago class-wc-ajax.php 1 month ago class-wc-auth.php 1 year ago class-wc-autoloader.php 9 months ago class-wc-background-emailer.php 2 months ago class-wc-background-updater.php 5 years ago class-wc-brands-brand-settings-manager.php 1 year ago class-wc-brands-coupons.php 1 year ago class-wc-brands.php 1 month ago class-wc-breadcrumb.php 4 months ago class-wc-cache-helper.php 1 month ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 3 months ago class-wc-cart-totals.php 11 months ago class-wc-cart.php 1 month ago class-wc-checkout.php 1 month ago class-wc-cli.php 10 months ago class-wc-comments.php 4 months ago class-wc-countries.php 2 months ago class-wc-coupon.php 2 months ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 1 year ago class-wc-customer.php 1 day ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 2 years ago class-wc-deprecated-filter-hooks.php 3 months ago class-wc-discounts.php 11 months ago class-wc-download-handler.php 1 month ago class-wc-emails.php 1 month ago class-wc-embed.php 1 year ago class-wc-form-handler.php 3 months ago class-wc-frontend-scripts.php 2 months ago class-wc-geo-ip.php 9 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 2 months ago class-wc-https.php 3 years ago class-wc-install.php 6 days ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 4 months ago class-wc-meta-data.php 1 month ago class-wc-order-factory.php 2 months ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 5 months ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 1 month ago class-wc-order-item-shipping.php 5 months ago class-wc-order-item-tax.php 1 month ago class-wc-order-item.php 1 month ago class-wc-order-query.php 1 month ago class-wc-order-refund.php 1 year ago class-wc-order.php 1 month ago class-wc-payment-gateways.php 1 month ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 2 months ago class-wc-post-types.php 1 month ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 10 months ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 1 year ago class-wc-product-attribute.php 4 months ago class-wc-product-download.php 4 months ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 3 months ago class-wc-product-grouped.php 3 months ago class-wc-product-query.php 4 months ago class-wc-product-simple.php 11 months ago class-wc-product-variable.php 1 month ago class-wc-product-variation.php 1 month ago class-wc-query.php 1 month ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 2 years ago class-wc-register-wp-admin-settings.php 5 years ago class-wc-rest-authentication.php 2 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 3 months ago class-wc-shipping-rate.php 1 year ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 7 months ago class-wc-shipping.php 2 months ago class-wc-shortcodes.php 1 year ago class-wc-structured-data.php 1 month ago class-wc-tax.php 2 months ago class-wc-template-loader.php 7 months ago class-wc-tracker.php 1 month ago class-wc-validation.php 2 years ago class-wc-webhook.php 1 month ago class-woocommerce.php 1 day ago wc-account-functions.php 1 month ago wc-attribute-functions.php 1 month ago wc-brands-functions.php 1 year ago wc-cart-functions.php 1 month ago wc-conditional-functions.php 11 months ago wc-core-functions.php 2 months ago wc-coupon-functions.php 5 months ago wc-deprecated-functions.php 1 month ago wc-formatting-functions.php 1 month ago wc-interactivity-api-functions.php 2 months ago wc-notice-functions.php 5 months ago wc-order-functions.php 1 month ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 4 months ago wc-page-functions.php 1 month ago wc-product-functions.php 2 months ago wc-rest-functions.php 7 months ago wc-stock-functions.php 7 months ago wc-template-functions.php 1 month ago wc-template-hooks.php 10 months ago wc-term-functions.php 2 months ago wc-update-functions.php 6 days ago wc-user-functions.php 1 month ago wc-webhook-functions.php 1 month ago wc-widget-functions.php 5 years ago
class-wc-product-attribute.php
380 lines
1 <?php
2 /**
3 * Represents a product attribute
4 *
5 * Attributes can be global (taxonomy based) or local to the product itself.
6 * Uses ArrayAccess to be BW compatible with previous ways of reading attributes.
7 *
8 * @package WooCommerce\Classes
9 * @version 3.0.0
10 * @since 3.0.0
11 */
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Product attribute class.
17 */
18 class WC_Product_Attribute implements ArrayAccess {
19
20 /**
21 * Data array.
22 *
23 * @since 3.0.0
24 * @var array
25 */
26 protected $data = array(
27 'id' => 0,
28 'name' => '',
29 'options' => array(),
30 'position' => 0,
31 'visible' => false,
32 'variation' => false,
33 );
34
35 /**
36 * Extra data array.
37 *
38 * @since 10.6.0
39 * @var array
40 */
41 protected $extra_data = array();
42
43 /**
44 * Return if this attribute is a taxonomy.
45 *
46 * @return boolean
47 */
48 public function is_taxonomy() {
49 return 0 < $this->get_id();
50 }
51
52 /**
53 * Get taxonomy name if applicable.
54 *
55 * @return string
56 */
57 public function get_taxonomy() {
58 return $this->is_taxonomy() ? $this->get_name() : '';
59 }
60
61 /**
62 * Get taxonomy object.
63 *
64 * @return array|null
65 */
66 public function get_taxonomy_object() {
67 global $wc_product_attributes;
68 return $this->is_taxonomy() ? $wc_product_attributes[ $this->get_name() ] : null;
69 }
70
71 /**
72 * Gets terms from the stored options.
73 *
74 * @return array|null
75 */
76 public function get_terms() {
77 if ( ! $this->is_taxonomy() || ! taxonomy_exists( $this->get_name() ) ) {
78 return null;
79 }
80 $terms = array();
81 foreach ( $this->get_options() as $option ) {
82 if ( is_int( $option ) ) {
83 $term = get_term_by( 'id', $option, $this->get_name() );
84 } else {
85 // Term names get escaped in WP. See sanitize_term_field.
86 $term = get_term_by( 'name', $option, $this->get_name() );
87
88 if ( ! $term || is_wp_error( $term ) ) {
89 $new_term = wp_insert_term( $option, $this->get_name() );
90 $term = is_wp_error( $new_term ) ? false : get_term_by( 'id', $new_term['term_id'], $this->get_name() );
91 }
92 }
93 if ( $term && ! is_wp_error( $term ) ) {
94 $terms[] = $term;
95 }
96 }
97 return $terms;
98 }
99
100 /**
101 * Gets slugs from the stored options, or just the string if text based.
102 *
103 * @return array
104 */
105 public function get_slugs() {
106 if ( ! $this->is_taxonomy() || ! taxonomy_exists( $this->get_name() ) ) {
107 return $this->get_options();
108 }
109 $terms = array();
110 foreach ( $this->get_options() as $option ) {
111 if ( is_int( $option ) ) {
112 $term = get_term_by( 'id', $option, $this->get_name() );
113 } else {
114 $term = get_term_by( 'name', $option, $this->get_name() );
115
116 if ( ! $term || is_wp_error( $term ) ) {
117 $new_term = wp_insert_term( $option, $this->get_name() );
118 $term = is_wp_error( $new_term ) ? false : get_term_by( 'id', $new_term['term_id'], $this->get_name() );
119 }
120 }
121 if ( $term && ! is_wp_error( $term ) ) {
122 $terms[] = $term->slug;
123 }
124 }
125 return $terms;
126 }
127
128 /**
129 * Returns all data for this object.
130 *
131 * @return array
132 */
133 public function get_data() {
134 return array_merge(
135 $this->extra_data,
136 $this->data,
137 array(
138 'is_visible' => $this->get_visible() ? 1 : 0,
139 'is_variation' => $this->get_variation() ? 1 : 0,
140 'is_taxonomy' => $this->is_taxonomy() ? 1 : 0,
141 'value' => $this->is_taxonomy() ? '' : wc_implode_text_attributes( $this->get_options() ),
142 )
143 );
144 }
145
146 /*
147 |--------------------------------------------------------------------------
148 | Setters
149 |--------------------------------------------------------------------------
150 */
151
152 /**
153 * Set extra data by key.
154 *
155 * @since 10.6.0
156 * @param string $key Extra data key.
157 * @param mixed $value Extra data value.
158 */
159 public function set_extra_data( string $key, $value ): void {
160 $this->extra_data[ $key ] = $value;
161 }
162
163 /**
164 * Set ID (this is the attribute ID).
165 *
166 * @param int $value Attribute ID.
167 */
168 public function set_id( $value ) {
169 $this->data['id'] = absint( $value );
170 }
171
172 /**
173 * Set name (this is the attribute name or taxonomy).
174 *
175 * @param string $value Attribute name.
176 */
177 public function set_name( $value ) {
178 $this->data['name'] = $value;
179 }
180
181 /**
182 * Set options.
183 *
184 * @param array $value Attribute options.
185 */
186 public function set_options( $value ) {
187 $this->data['options'] = $value;
188 }
189
190 /**
191 * Set position.
192 *
193 * @param int $value Attribute position.
194 */
195 public function set_position( $value ) {
196 $this->data['position'] = absint( $value );
197 }
198
199 /**
200 * Set if visible.
201 *
202 * @param bool $value If is visible on Product's additional info tab.
203 */
204 public function set_visible( $value ) {
205 $this->data['visible'] = wc_string_to_bool( $value );
206 }
207
208 /**
209 * Set if variation.
210 *
211 * @param bool $value If is used for variations.
212 */
213 public function set_variation( $value ) {
214 $this->data['variation'] = wc_string_to_bool( $value );
215 }
216
217 /*
218 |--------------------------------------------------------------------------
219 | Getters
220 |--------------------------------------------------------------------------
221 */
222
223 /**
224 * Get all extra data.
225 *
226 * @since 10.6.0
227 * @return array
228 */
229 public function get_all_extra_data() {
230 return $this->extra_data;
231 }
232
233 /**
234 * Get extra data by key.
235 *
236 * @since 10.6.0
237 * @param string $key Extra data key.
238 * @return mixed
239 */
240 public function get_extra_data( string $key ) {
241 return $this->extra_data[ $key ] ?? null;
242 }
243
244 /**
245 * Get the ID.
246 *
247 * @return int
248 */
249 public function get_id() {
250 return $this->data['id'];
251 }
252
253 /**
254 * Get name.
255 *
256 * @return string
257 */
258 public function get_name() {
259 return $this->data['name'];
260 }
261
262 /**
263 * Get options.
264 *
265 * @return array
266 */
267 public function get_options() {
268 return $this->data['options'];
269 }
270
271 /**
272 * Get position.
273 *
274 * @return int
275 */
276 public function get_position() {
277 return $this->data['position'];
278 }
279
280 /**
281 * Get if visible.
282 *
283 * @return bool
284 */
285 public function get_visible() {
286 return $this->data['visible'];
287 }
288
289 /**
290 * Get if variation.
291 *
292 * @return bool
293 */
294 public function get_variation() {
295 return $this->data['variation'];
296 }
297
298 /*
299 |--------------------------------------------------------------------------
300 | ArrayAccess/Backwards compatibility.
301 |--------------------------------------------------------------------------
302 */
303
304 /**
305 * OffsetGet.
306 *
307 * @param string $offset Offset.
308 * @return mixed
309 */
310 #[\ReturnTypeWillChange]
311 public function offsetGet( $offset ) {
312 switch ( $offset ) {
313 case 'is_variation':
314 return $this->get_variation() ? 1 : 0;
315 case 'is_visible':
316 return $this->get_visible() ? 1 : 0;
317 case 'is_taxonomy':
318 return $this->is_taxonomy() ? 1 : 0;
319 case 'value':
320 return $this->is_taxonomy() ? '' : wc_implode_text_attributes( $this->get_options() );
321 default:
322 if ( is_callable( array( $this, "get_$offset" ) ) ) {
323 return $this->{"get_$offset"}();
324 }
325 if ( isset( $this->extra_data[ $offset ] ) ) {
326 return $this->extra_data[ $offset ];
327 }
328 break;
329 }
330 return '';
331 }
332
333 /**
334 * OffsetSet.
335 *
336 * @param string $offset Offset.
337 * @param mixed $value Value.
338 */
339 #[\ReturnTypeWillChange]
340 public function offsetSet( $offset, $value ) {
341 switch ( $offset ) {
342 case 'is_variation':
343 $this->set_variation( $value );
344 break;
345 case 'is_visible':
346 $this->set_visible( $value );
347 break;
348 case 'value':
349 $this->set_options( $value );
350 break;
351 default:
352 if ( is_callable( array( $this, "set_$offset" ) ) ) {
353 $this->{"set_$offset"}( $value );
354 break;
355 }
356 $this->extra_data[ $offset ] = $value;
357 break;
358 }
359 }
360
361 /**
362 * OffsetUnset.
363 *
364 * @param string $offset Offset.
365 */
366 #[\ReturnTypeWillChange]
367 public function offsetUnset( $offset ) {}
368
369 /**
370 * OffsetExists.
371 *
372 * @param string $offset Offset.
373 * @return bool
374 */
375 #[\ReturnTypeWillChange]
376 public function offsetExists( $offset ) {
377 return in_array( $offset, array_merge( array( 'is_variation', 'is_visible', 'is_taxonomy', 'value' ), array_keys( $this->data ), array_keys( $this->extra_data ) ), true );
378 }
379 }
380