WC_Product::set_attributes()publicWC 3.0.0

Set product attributes.

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 unique key to allow clearing old ones after a set.

Method of the class: WC_Product{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Product = new WC_Product();
$WC_Product->set_attributes( $raw_attributes );
$raw_attributes(array) (required)
Array of WC_Product_Attribute objects.

Changelog

Since 3.0.0 Introduced.

WC_Product::set_attributes() code WC 8.6.1

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 );
}