WC_Product_Variation::set_attributes()publicWC 1.0

Set attributes. Unlike the parent product which uses terms, variations are assigned specific attributes using name value pairs.

Method of the class: WC_Product_Variation{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Product_Variation = new WC_Product_Variation();
$WC_Product_Variation->set_attributes( $raw_attributes );
$raw_attributes(array) (required)
array of raw attributes.

WC_Product_Variation::set_attributes() code WC 9.0.1

public function set_attributes( $raw_attributes ) {
	$raw_attributes = (array) $raw_attributes;
	$attributes     = array();

	foreach ( $raw_attributes as $key => $value ) {
		// Remove attribute prefix which meta gets stored with.
		if ( 0 === strpos( $key, 'attribute_' ) ) {
			$key = substr( $key, 10 );
		}
		$attributes[ $key ] = $value;
	}
	$this->set_prop( 'attributes', $attributes );
}