Hi @zotezo,
Thanks for providing the details of your issue. From what you’ve described, the behavior seems to stem from how WooCommerce manages order item meta data—particularly for items linked to actual WooCommerce products.
Using wc_update_order_item_meta() may not always update existing meta as expected because WooCommerce can cache this data to improve performance. When meta information is already cached, updates might not reflect immediately, even if the underlying data is changed in the database. This is more commonly observed with product-related order items due to their deeper integration within WooCommerce’s system.
To ensure your meta data is consistently updated, it’s better to use the update_meta_data() method directly on the order item object, and then call save(). This method avoids the caching issue and guarantees that your meta field is updated. You can use the following approach:
$item = new WC_Order_Item_Product( $item_id );
$item->update_meta_data( '_my_custom_key', $mydata, true ); // 'true' forces overwrite
$item->save();
This ensures your custom meta key is updated each time, regardless of whether it already exists.
Please note that handling custom code like this is outside the usual support scope on this forum. For further help, feel free to connect with other developers and community members via our Slack channel: https://woocommerce.com/community-slack/
And if you’ve found our support helpful and enjoy working with WooCommerce, we’d really appreciate your review: https://wordpress.org/support/plugin/woocommerce/reviews/#new-post