WC_Product::set_attributes PHP Method

set_attributes() public method

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.
Since: 2.7.0
public set_attributes ( array $raw_attributes )
$raw_attributes array Array of WC_Product_Attribute objects.
    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);
    }
WC_Product