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.


Top ↑

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

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.