Support for order_item to be init from obj with `order_item_id` prop.

Also set metadata cache if metadata prop is present in initial item.
This commit is contained in:
vedanshujain 2020-06-24 18:51:00 +05:30
parent 22212c7065
commit e9d97d97e7
1 changed files with 8 additions and 0 deletions

View File

@ -64,10 +64,18 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
$this->set_id( $item->get_id() );
} elseif ( is_numeric( $item ) && $item > 0 ) {
$this->set_id( $item );
} elseif ( is_object( $item ) && isset( $item->order_item_id ) ) {
// TODO: Could this cause issue with child classes. Should be fine as long as they are calling parent::__construct.
$this->set_id( $item->order_item_id );
} else {
$this->set_object_read( true );
}
if ( isset( $item->metadata ) && is_array( $item->metadata ) ) {
$meta_cache_key = $this->get_meta_cache_key();
wp_cache_set( $meta_cache_key, $item->metadata, $this->cache_group );
}
$type = 'line_item' === $this->get_type() ? 'product' : $this->get_type();
$this->data_store = WC_Data_Store::load( 'order-item-' . $type );
if ( $this->get_id() > 0 ) {