• Resolved Kudratullah

    (@mhamudul_hk)


    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_thankyou hook then it works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there 👋

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Since it’s been a while since we last heard back from you, I’m going to mark this thread resolved.

    Hopefully, you were able to find a solution to your problem! If you have further questions, please feel free to open a new topic.

    Cheers! 🙂

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.