WC_Order_Item::offsetGet PHP Method

offsetGet() public method

offsetGet for ArrayAccess
public offsetGet ( string $offset ) : mixed
$offset string
return mixed
    public function offsetGet($offset)
    {
        if ('item_meta_array' === $offset) {
            $return = array();
            foreach ($this->meta_data as $meta) {
                $return[$meta->id] = $meta;
            }
            return $return;
        }
        $meta_values = wp_list_pluck($this->meta_data, 'value', 'key');
        if ('item_meta' === $offset) {
            return $meta_values;
        } elseif (array_key_exists($offset, $this->data)) {
            return $this->data[$offset];
        } elseif (array_key_exists('_' . $offset, $meta_values)) {
            // Item meta was expanded in previous versions, with prefixes removed. This maintains support.
            return $meta_values['_' . $offset];
        }
        return null;
    }

Usage Example

 /**
  * offsetGet for ArrayAccess/Backwards compatibility.
  * @deprecated Add deprecation notices in future release.
  * @param string $offset
  * @return mixed
  */
 public function offsetGet($offset)
 {
     if ('cost' === $offset) {
         $offset = 'total';
     }
     return parent::offsetGet($offset);
 }
All Usage Examples Of WC_Order_Item::offsetGet