Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Update Line Item Meta Data – WooCommerce API

For some reason, you have to double the arrays, maybe this doesn’t affect you as you are referencing the firt element. I use this in PHP:

function saveMetaItem($id_order,$id_item,$id_product,$meta_key,$meta_value){
    $woo = new wooclient();
    $data = array(
        'line_items' => array(array(
                       'id' => $id_item,
                       'product_id' => $id_product,
                       'meta_data' => array(array(
                            'key' => $meta_key,
                            'value' => $meta_value
                               ))
                       ))
    );
    $result = $woo->put('orders/'.$id_order, $data);
    return $result;
}

Notice the double array() calls in both line_items and meta_data. Also provide both id and product_id. Convert that to JSON and your done 😉

Related Posts:

  1. Cant create or update meta fields using WordPress REST API
  2. WP-API + JS Backbone client – how to update post meta
  3. How to update/insert custom field(post meta) data with wordpress REST API?
  4. WP REST API “rest_no_route” when trying to update meta
  5. Options to get my custom post type metadata via the WordPress API
  6. Is it possible to update a post meta field through REST API if the format of it when registered is nested?
  7. Mass importing json data into custom fields (postmeta)
  8. Unknown characters added to meta data values
  9. How to properly use oneOf and anyOf in Rest Schema?
  10. Bulk Update Post Meta Values from Different Post via Rest Api
  11. How to register post meta with multi level arrays?
  12. How to add a post’s view count into the WordPress API response
  13. Attachment metadata has value of ‘1’
  14. Best Way to detect unique posts in wp rest api
  15. WP-API : post_meta not updated… but have another entry
  16. Hiding WordPress REST API v2 endpoints from public viewing
  17. How can I get the post ID from a WP_Query loop?
  18. How to edit a post meta data in a Gutenberg Block?
  19. How to loop through JSON data in wordpress WP REST API
  20. How to update/delete array in post meta value?
  21. WP REST API V2 – Modifying responses
  22. How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
  23. How to store post meta in an array?
  24. adding a URL to a post meta
  25. update_post_meta() not working when used with WordPress action
  26. Adding meta data to an attachment post
  27. wordpress custom endpoint multiple params
  28. WordPress REST API “rest_authentication_errors” doesn’t work external queries?
  29. Problem With Order Item Meta In Woocommerce
  30. Job of meta_key meta_value fields in database tables
  31. How to retrieve custom meta term of category taxonomy from WP Rest API?
  32. Gutenberg Custom Block Getting All Posts
  33. Best way to save postmeta
  34. How to add meta data to WordPress posts?
  35. How to update Post Meta values through the comment system
  36. Filtering multiple meta_values
  37. How to add WP API and JS featured image attachment
  38. How add post_meta from user_meta?
  39. How can I get my iFrame to work with url from post_meta?
  40. How to use update_post_meta() function properly?
  41. Update post meta in woocommerce order frontend
  42. populate post meta in gravity forms [closed]
  43. How to display post view count by date, week and month?
  44. How can I filter posts when the meta_value is a serialize object?
  45. Get User Post if Private
  46. post meta parameter in post custom-post-type endpoint with restapi
  47. How to receive all the meta information of a post ?
  48. Add Data to Response of WP-JSON Root
  49. Compare old meta with new post meta
  50. get_post_meta($post->ID) returns empty string when in preview mode of custom post type
  51. Read post meta values, only if posts are public
  52. Time & Date on Post – Time Ago Custom Function
  53. Updating my Post when expiry date is past
  54. Mass removing CSS from 1,700 post [closed]
  55. Help with Post Meta
  56. How do I manage custom meta in post revisions in the Block Editor era?
  57. Generate metadata for cloud images
  58. Migrating meta value to new meta value
  59. Insert multiple metas in one time
  60. How to extract data from a post meta
  61. WP REST API and Access-Control-Allow-Origin
  62. count post meta values
  63. Correct meta of Writing Meta Tags
  64. Get post_meta from specific post [closed]
  65. How to add tags to post from frontend?
  66. Retrieve user_meta and copy to post_meta
  67. getting the post_id from the post_meta
  68. troubles with get_post_meta (and saving it)
  69. Flatten Responses returned via WP REST API via WP_Error for obfuscation
  70. WordPress REST API – get custom taxonomy category posts
  71. How to merge the array values in foreach?
  72. How to exclude posts by meta key value in the_post_navigation next prev links?
  73. Remove unwanted fields from WP API response
  74. update_post_meta not working with transition_comment_status
  75. WordPress API “code”:”rest_no_route” with Custom Route
  76. Update post meta date always store 1970-01-07
  77. Is it possible to pass an whole array using custom field in wordpress?
  78. How do I update a specific value within array in a products metadata?
  79. Optimize WP Meta Query for large amount of post meta?
  80. rendering open graph meta tags in wordpress
  81. Should I edit a user meta field with PUT, PATCH, or POST and WP::Editable
  82. Restore deleted _thumbnail_id in postmeta table
  83. Hide the_meta if no value
  84. php wp_insert data on front using a form
  85. Updating post_meta when updating a setting with the Settings API
  86. How to show specific meta keys of all posts in admin panel?
  87. wp_schedule_event not working
  88. Media library orphans
  89. WordPress join posts with meta values of array type
  90. How to make certain content of the post noindex and no follow. not entire post?
  91. Export posts with postmeta without ID?
  92. How can I display my meta value in a textarea? [closed]
  93. delete blank space in post_meta empty [closed]
  94. Auto save title as custom meta field value
  95. API request forbidden when requesting from same domain
  96. How to show wordpress post in the site based on custom field value?
  97. How can I enforce user to use Application password to generate JWT token? [closed]
  98. Extend file format support for post thumbnails
  99. Why isn’t my embed_video WYSIWYG field updating when using update_post_meta?
  100. rest_api_init is not getting invoked inside a Class
Categories post-meta Tags post-meta, rest-api, wp-api
Edit custom post type admin menu link
How to create a WordPress Post Filter that users can use to filter posts by year?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress