WordPress at Your Fingertips
function is not described

WC_Product::set_attributes() public WC 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 unqiue key to allow clearing old ones after a set.

{} It's a method of the class: WC_Product{}

No Hooks.

Return

null. Nothing.

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.

Code of WC_Product::set_attributes() WC 5.5.2

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