protected function read_attributes(&$product)
{
$meta_values = maybe_unserialize(get_post_meta($product->get_id(), '_product_attributes', true));
if ($meta_values) {
$attributes = array();
foreach ($meta_values as $meta_value) {
if (!empty($meta_value['is_taxonomy'])) {
if (!taxonomy_exists($meta_value['name'])) {
continue;
}
$options = wc_get_object_terms($product->get_id(), $meta_value['name'], 'term_id');
} else {
$options = wc_get_text_attributes($meta_value['value']);
}
$attribute = new WC_Product_Attribute();
$attribute->set_id(wc_attribute_taxonomy_id_by_name($meta_value['name']));
$attribute->set_name($meta_value['name']);
$attribute->set_options($options);
$attribute->set_position($meta_value['position']);
$attribute->set_visible($meta_value['is_visible']);
$attribute->set_variation($meta_value['is_variation']);
$attributes[] = $attribute;
}
$product->set_attributes($attributes);
}
}