WooCommerce - excelling eCommerce
get_item_meta returns empty (6 posts)

  1. Fahad Mahmood
    Posted 2 years ago #

    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);
    					foreach($has_meta as $imeta){


  2. jimlongo
    Posted 2 years ago #

    I've found that sometimes rather than rely on WC classes it's easier to do a wp->db query.

  3. Fahad Mahmood
    Posted 2 years ago #

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

  4. jimlongo
    Posted 2 years ago #

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

  5. Fahad Mahmood
    Posted 2 years ago #

    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.

  6. Vinze
    Posted 2 years ago #

    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..

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.