WordPress at Your Fingertips
function is not described

WC_Product_Data_Store_CPT::read_attributes() protected WC 1.0

Read attributes from post meta.

{} It's a method of the class: WC_Product_Data_Store_CPT{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->read_attributes( $product );
$product(WC_Product) (required) (passed by reference — &)
Product object.

Code of WC_Product_Data_Store_CPT::read_attributes() WC 5.6.0

protected function read_attributes( &$product ) {
	$meta_attributes = get_post_meta( $product->get_id(), '_product_attributes', true );

	if ( ! empty( $meta_attributes ) && is_array( $meta_attributes ) ) {
		$attributes = array();
		foreach ( $meta_attributes as $meta_attribute_key => $meta_attribute_value ) {
			$meta_value = array_merge(
				array(
					'name'         => '',
					'value'        => '',
					'position'     => 0,
					'is_visible'   => 0,
					'is_variation' => 0,
					'is_taxonomy'  => 0,
				),
				(array) $meta_attribute_value
			);

			// Check if is a taxonomy attribute.
			if ( ! empty( $meta_value['is_taxonomy'] ) ) {
				if ( ! taxonomy_exists( $meta_value['name'] ) ) {
					continue;
				}
				$id      = wc_attribute_taxonomy_id_by_name( $meta_value['name'] );
				$options = wc_get_object_terms( $product->get_id(), $meta_value['name'], 'term_id' );
			} else {
				$id      = 0;
				$options = wc_get_text_attributes( $meta_value['value'] );
			}

			$attribute = new WC_Product_Attribute();
			$attribute->set_id( $id );
			$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 );
	}
}