WordPress at Your Fingertips
function is not described

WC_Data::read_meta_data() public WC 2.6.0

Read Meta Data from the database. Ignore any internal properties. Uses it's own caches because get_metadata does not provide meta_ids.

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

No Hooks.

Return

null. Nothing.

Usage

$WC_Data = new WC_Data();
$WC_Data->read_meta_data( $force_read );
$force_read(true|false)
True to force a new DB read (and update cache).
Default: false

Changelog

Since 2.6.0 Introduced.

Code of WC_Data::read_meta_data() WC 5.8.0

public function read_meta_data( $force_read = false ) {
	$this->meta_data = array();
	$cache_loaded    = false;

	if ( ! $this->get_id() ) {
		return;
	}

	if ( ! $this->data_store ) {
		return;
	}

	if ( ! empty( $this->cache_group ) ) {
		// Prefix by group allows invalidation by group until https://core.trac.wordpress.org/ticket/4476 is implemented.
		$cache_key = $this->get_meta_cache_key();
	}

	if ( ! $force_read ) {
		if ( ! empty( $this->cache_group ) ) {
			$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
			$cache_loaded = ! empty( $cached_meta );
		}
	}

	// We filter the raw meta data again when loading from cache, in case we cached in an earlier version where filter conditions were different.
	$raw_meta_data = $cache_loaded ? $this->data_store->filter_raw_meta_data( $this, $cached_meta ) : $this->data_store->read_meta( $this );

	if ( $raw_meta_data ) {
		foreach ( $raw_meta_data as $meta ) {
			$this->meta_data[] = new WC_Meta_Data(
				array(
					'id'    => (int) $meta->meta_id,
					'key'   => $meta->meta_key,
					'value' => maybe_unserialize( $meta->meta_value ),
				)
			);
		}

		if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
			wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
		}
	}
}