WC_Product_Variation::set_attributes │ public │ WC 3.0.0

Set attributes. Unlike the parent product which uses terms, variations are assigned specific attributes using name-value pairs. Taxonomy attribute values must use term slugs, which can be URL-encoded and differ from the term name.

For example, if a global "Size" attribute has a term named "7½", whose stored slug is "7%c2%bd", configure the variation using that term slug:

$variation->set_attributes(

array(
	'pa_size' => '7%c2%bd',
)

);

Метод класса: WC_Product_Variation{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WC_Product_Variation = new WC_Product_Variation();
$WC_Product_Variation->set_attributes( $raw_attributes );
$raw_attributes(массив) (обязательный)
Array of raw attributes.

Список изменений

С версии 3.0.0 Введена.

Код WC_Product_Variation::set_attributes() WC 11.3.0

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