Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get order_item_id WooCommerce

I need to be able to get order_item_id, the unique value applied to each item in each order. This is what I have so far:

        global $wpdb;
    $order = new WC_Order( $order_id );
    $items = $order->get_items(); 
        foreach ( $items as $item ) {
            $product_id = $item['product_id'];
            $item_id = $item['item_id'];

The last line in the above code gets order_item_id. It normally wouldn't work but it works because I've edited get_items in class-wc-order and included:

        $items[ $item->order_item_id ]['item_id'] = $item->order_item_id;

What I want to know is how can I get order_item_id without having to edit class-wc-order. Is there any easy way?

Thanks!

like image 313
user2903890 Avatar asked Oct 21 '13 15:10

user2903890


1 Answers

This may be already too late for your project but may be useful for others:

foreach ($items as $key => $product ) 

The $key variable is the item_idyou are looking for.

like image 54
user3367143 Avatar answered Sep 20 '22 14:09

user3367143