September 19, 2013

WooCommerce Version 2.0.12 – get_item_meta

WooCommerce Version 2.0.12

File: classes/class-wc-order.php
Function: get_item_meta
Issue: It returns empty although itemdata table have records.
Ref: Support

Suggested Fix: There is another function which is available in the same class with the name “has_meta”. We can use it as an else case.

Insert the following code in function “get_items” after this line
$items[ $item->order_item_id ]['item_meta'] = $this->get_item_meta( $item->order_item_id );
if(empty($items[ $item->order_item_id ]['item_meta'])){
$has_meta = $this->has_meta($item->order_item_id);
if(!empty($has_meta)){
foreach($has_meta as $imeta){
$items[$item->order_item_id]['item_meta'][$imeta['meta_key']]=array($imeta['meta_value']);
}
}
}

Expected Output:
Array
(
[3] => Array
(
[name] => Product Name
[type] => line_item
[item_meta] => Array
(
[_line_subtotal] => 168
[_line_subtotal_tax] => 0
[_line_tax] => 0
[_line_total] => 168
[_product_id] => 53
[_qty] => 1
[_tax_class] =>
[_variation_id] =>
)
[line_subtotal] => 168
[line_subtotal_tax] => 0
[line_tax] => 0
[line_total] => 168
[product_id] => 53
[qty] => 1
[tax_class] =>
[variation_id] =>
)
)

Last updated: March 19, 2014