WordPress.org

Support

Support » Plugins and Hacks » get_item_meta returns empty

get_item_meta returns empty

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

    I am integrating an API with WooCommerce so its a requirement but this function is not working as expected.

    What i did,
    After this line:
    $items[ $item->order_item_id ]['item_meta'] = $this->get_item_meta( $item->order_item_id );
    I have inserted a code snippet, please confirm is it right way or any other recommendation from your side?

    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']);
    					}
    				}
    			}

    http://wordpress.org/extend/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’ve found that sometimes rather than rely on WC classes it’s easier to do a wp->db query.

    You are right, but it was a requirement that use WC classes to integrate an API for it.

    do you have the global $woocommerce declared on that page?

    No, in fact orders detail was required and when i fetched orders and tried to retrieve cart items so that empty was array. I used WC by creating an object.

    Did you found a solution for this issue? I’m having the same problem!

    add_action( 'woocommerce_new_order_item', 'WCWF_new_order' , 10, 3 );
    
    function WCWF_new_order( $item_id, $item, $order_id ) {
    	$order 	= new WC_Order( $order_id );
    	$item_meta = $order->get_item_meta( $item_id );
    }

    Unfortunately $item_meta doesn’t contain anything..

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_item_meta returns empty’ is closed to new replies.