wc_add_order_item_meta()WC 1.0

WooCommerce Order Item Meta API - Add term meta.

No Hooks.

Return

Int. New row ID or 0.

Usage

wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique );
$item_id(int) (required)
Item ID.
$meta_key(string) (required)
Meta key.
$meta_value(mixed) (required)
Meta value.
$unique(true|false)
If meta data should be unique .
Default: false)

wc_add_order_item_meta() code WC 9.4.2

function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) {
	$data_store = WC_Data_Store::load( 'order-item' );
	$meta_id    = $data_store->add_metadata( $item_id, $meta_key, $meta_value, $unique );

	if ( $meta_id ) {
		WC_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache.
		return $meta_id;
	}
	return 0;
}