php - Does WooCommerce Order Item Meta value need to be a string? -
this question out of pure curiosity.
as stated in title, woocommerce order item meta need string.
hypothetically speaking have meta data array?
if so, need go things differently?
i know in order add new meta data need use along lines of following code:
wc_add_order_item_meta($item_id, 'mymetaname', 'john doe', true);
but, know if possible have meta data of different data type.
any input appreciated!
yes can array.
if database table '_line_tax_data'
meta_key
serialized array meta_value
this:
a:2:{s:5:"total";a:1:{i:2;s:4:"1.92";}s:8:"subtotal";a:1:{i:2;s:3:"2.4";}}
and in source code:
/** * woocommerce order item meta api - add term meta. * * @access public * @param mixed $item_id * @param mixed $meta_key * @param mixed $meta_value * @param bool $unique (default: false) * @return int new row id or 0 */ function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) { $data_store = wc_data_store::load( 'order-item' ); if ( $meta_id = $data_store->add_metadata( $item_id, $meta_key, $meta_value, $unique ) ) { $cache_key = wc_cache_helper::get_cache_prefix( 'order-items' ) . 'object_meta_' . $item_id; wp_cache_delete( $cache_key, 'order-items' ); return $meta_id; } return 0; }
Comments
Post a Comment