WC_Product::set_attributes( array $raw_attributes )
Set product attributes.
Description Description
Attributes are made up of: id – 0 for product level attributes. ID for global attributes. name – Attribute name. options – attribute value or array of term ids/names. position – integer sort order. visible – If visible on frontend. variation – If used for variations. Indexed by unqiue key to allow clearing old ones after a set.
Parameters Parameters
- $raw_attributes
-
(Required) Array of WC_Product_Attribute objects.
Source Source
File: includes/abstracts/abstract-wc-product.php
public function set_attributes( $raw_attributes ) { $attributes = array_fill_keys( array_keys( $this->get_attributes( 'edit' ) ), null ); foreach ( $raw_attributes as $attribute ) { if ( is_a( $attribute, 'WC_Product_Attribute' ) ) { $attributes[ sanitize_title( $attribute->get_name() ) ] = $attribute; } } uasort( $attributes, 'wc_product_attribute_uasort_comparison' ); $this->set_prop( 'attributes', $attributes ); }
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |