WC_Product_Variation::set_attributes( array $raw_attributes )

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


Description Description


Parameters Parameters

$raw_attributes

(Required) array of raw attributes.


Top ↑

Source Source

File: includes/class-wc-product-variation.php

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

Top ↑

User Contributed Notes User Contributed Notes

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