WordPress at Your Fingertips
function is not described

WC_Data::add_meta_data() public WC 2.6.0

Add meta data.

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

No Hooks.

Return

null. Nothing.

Usage

$WC_Data = new WC_Data();
$WC_Data->add_meta_data( $key, $value, $unique );
$key(string) (required)
Meta key.
$value(string|array) (required)
Meta value.
$unique(true|false)
Should this be a unique key?.
Default: false

Changelog

Since 2.6.0 Introduced.

Code of WC_Data::add_meta_data() WC 5.8.0

public function add_meta_data( $key, $value, $unique = false ) {
	if ( $this->is_internal_meta_key( $key ) ) {
		$function = 'set_' . $key;

		if ( is_callable( array( $this, $function ) ) ) {
			return $this->{$function}( $value );
		}
	}

	$this->maybe_read_meta_data();
	if ( $unique ) {
		$this->delete_meta_data( $key );
	}
	$this->meta_data[] = new WC_Meta_Data(
		array(
			'key'   => $key,
			'value' => $value,
		)
	);
}