WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
get_item_meta returns empty (6 posts)

  1. Fahad Mahmood
    Member
    Posted 1 year 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);
    				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/

  2. jimlongo
    Member
    Posted 1 year ago #

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

  3. Fahad Mahmood
    Member
    Posted 1 year ago #

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

  4. jimlongo
    Member
    Posted 1 year ago #

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

  5. Fahad Mahmood
    Member
    Posted 1 year 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
    Member
    Posted 9 months 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

About this Topic

Tags

No tags yet.