WC_Order_item::get_id() return 0 inside woocommerce_checkout_order_processed hoo
-
Hi,
i was trying to loop throw order items and set some data in in order item meta along with some custom data insertion to a custom table with the snippet bellow.
but WC_Order_Item_Product::get_id() or WC_Order_Item::get_id() return zero.
also the items array key indicates that the line item is not saved.add_action( 'woocommerce_checkout_order_processed', function( $order_id, $posted_data, $order ) { $order = wc_get_order( $order_id ); $items = $order->get_items( 'line_item' ); if ( ! empty( $items ) ) { foreach ( $items as $item_id => $item ) { // here i'm getting 0 return from the get_id method. $order_item_id = $item->get_id(); // and also, the $item_id is new:line_items0 } } }, 100, 3 );But if i use the
woocommerce_before_thankyouhook then it works.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘WC_Order_item::get_id() return 0 inside woocommerce_checkout_order_processed hoo’ is closed to new replies.