wc_add_order_item_meta

WooCommerce Order Item Meta API - Add term meta.

Description

(int) wc_add_order_item_meta( (mixed) $item_id, (mixed) $meta_key, (mixed) $meta_value, (bool) $unique = false ); 

Returns (int)

New row ID or 0

Parameters (4)

0. $item_id (mixed)
The item id.
1. $meta_key (mixed)
The meta key.
2. $meta_value (mixed)
The meta value.
3. $unique — Optional. (bool) => false
(default: false)

Usage

  1. if ( !function_exists( 'wc_add_order_item_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-item-functions.php'; 
  3.  
  4. // The item id. 
  5. $item_id = null; 
  6.  
  7. // The meta key. 
  8. $meta_key = null; 
  9.  
  10. // The meta value. 
  11. $meta_value = null; 
  12.  
  13. // (default: false) 
  14. $unique = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wc_add_order_item_meta($item_id, $meta_key, $meta_value, $unique); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-item-functions.php  
  1. function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) { 
  2. $data_store = WC_Data_Store::load( 'order-item' ); 
  3. if ( $meta_id = $data_store->add_metadata( $item_id, $meta_key, $meta_value, $unique ) ) { 
  4. $cache_key = WC_Cache_Helper::get_cache_prefix( 'order-items' ) . 'object_meta_' . $item_id; 
  5. wp_cache_delete( $cache_key, 'order-items' ); 
  6. return $meta_id; 
  7. return 0;