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

Woocommerce Retrieving custom field value from orders

Some basic issues with code. Since this hook do not have any data supplied to function, you need to get current user logged in.

Secondly, as already mentioned by @antti, get_post_meta accepts first parameter as post id (in this case order id), single value.

function return_s_key_field() {

$orders = wc_get_orders(array(
    'customer_id' => get_current_user_id(),
    'return' => 'ids',
))

$meta_data = array();

foreach ($orders as $order_id) {
  $meta_data[$order_id] = get_post_meta($order_id, 's_key', true);  
}

// var_dump($meta_data);

}
add_action( 'woocommerce_after_available_downloads', 'return_s_key_field' );

Try un-commenting var_dump and then use that data however it is required.

Related Posts:

  1. How to access custom order item meta data from a meta key in WooCommerce?
  2. Save Custom Fields for Variations Product
  3. Adding existing user custom field value to a woocommerce product [closed]
  4. Adding Custom Text Area to WooCommerce Product
  5. WooCommerce conditional required checkout fields [closed]
  6. Include woocommerce custom field value in front-end search result
  7. woocommerce product custom field
  8. How to get customfield value by woocommerce product ID
  9. Conditionally hide or show woocommerce product variation in fontend by custom field
  10. Woocommerce: Custom fields and email shortcodes, ec_custom_field
  11. Bulk remove post meta
  12. How to create html block to display extra information on woocommerce single product page
  13. Display WP-Types custom fields in post [closed]
  14. Modifying custom order item meta from admin order view
  15. How to create a dropdown select of all items in an ACF field group
  16. How do I add an image upload, custom field to a WooCommerce product?
  17. WooCommerce – Adding Custom Fields To Invoice
  18. Woocommerce Product Custom Select List (not variation)
  19. jQuery – Automatic event trigger does not **really** check my form
  20. How to add new field to the account address?
  21. How to display custom field in woocommerce email orders? [closed]
  22. Update custom field values on edit address page woocommerce
  23. Woocommerce frontend edit custom fields
  24. Is it possible to add Term Meta Fields to a WooCommerce Attribute?
  25. Why does my numeric meta query work only on one meta key and not the other?
  26. Update custom field on the fly
  27. (woocommerce) How to get product id form order id & then retrieve custom meta linked to product?
  28. How to delete WooCommerce Products than have a specific custom field?
  29. WooCommerce 3 get custom variation on process order [closed]
  30. How to save array option as text and not integer?
  31. Use a different catalog image than the featured image
  32. Check if value exists before saving
  33. Add Custom field under the post title [closed]
  34. woocommerce how in checkout to add my custom field check box, and when i check it hide the shipping adress and add tax 19% [closed]
  35. price calculation from custom field (woocommerce) [closed]
  36. Hiding custom fields when content is empty [closed]
  37. Cannot save values to custom fields for variations on Woocommerce 2.4.6
  38. Send checkout page custom field in order email
  39. Extract array from custom field
  40. Assign class to Drop Down Selections in WooCommerce Products Custom Fields
  41. Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
  42. WP_Query – Order results by meta value
  43. Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
  44. getting all values for a custom field key (cross-post)
  45. How to add a custom field in the advanced menu properties?
  46. Custom query with orderby meta_value of custom field
  47. How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
  48. Using meta query (‘meta_query’) with a search query (‘s’)
  49. Can I exclude a post by meta key using pre_get_posts function?
  50. Add validation and error handling when saving custom fields?
  51. Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
  52. Show Custom Fields in Quick Edit
  53. Where are custom field values stored in the database
  54. Validating Custom Meta Box Values & Required Fields
  55. How to display custom field in woocommerce orders in admin panel?
  56. Max length of meta_value
  57. Add custom fields to wp native gallery settings
  58. How to fix missing custom fields after upgrading to WordPress 4.8.1?
  59. How to enable custom fields for pages (if not a bad practice)?
  60. How can I add extra attribute in the ‘Page Attribute’ section in wp-admin for pages?
  61. Is there a way to set default custom fields when creating a post?
  62. Custom post meta field effect on the performance on the post
  63. How to get custom post meta using REST API
  64. Custom field/meta populated by dropdown of existing posts?
  65. Difference between meta keys with _ and without _ [duplicate]
  66. Is there any action filter/hook for validating a custom field before publishing the post?
  67. Remove Dimension from wp_get_attachment_image
  68. Orderby meta_value only returns posts that have existing meta_key
  69. Underscores in custom fields
  70. What is the index [0] for on post meta fields?
  71. What is “meta_input” parameter in wp_insert_post() used for?
  72. Query Posts or Get Posts by custom fields, possible?
  73. How to enable revisions for post meta data?
  74. Sortable Custom Columns in User Panel (users.php)?
  75. Any way to add custom options to Gallery Settings?
  76. The “_encloseme” Meta-Key Conundrum
  77. ORDER BY custom field value
  78. Individual Widgets per Page
  79. Add subtitle to Woocommerce product title
  80. Best way to programmatically remove a category/term from a post
  81. Importing data for advanced custom fields plugin?
  82. Gutenberg add a custom metabox to default blocks
  83. SQL Query to copy value of a meta_key into another meta_key
  84. ‘Preview Changes’ for custom meta boxes?
  85. Adding a custom field to the site identity menu
  86. Using TinyMce with textareas in meta boxes on custom post types
  87. Filter WP_Query for posts having a certain meta-value
  88. How to correctly call custom field dates into a posts_where filter using SQL statements
  89. Using get_post_meta with new_to_publish
  90. Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
  91. Add a Jquery Datepicker to custom field in post edit
  92. add meta box – custom field : which to choose?
  93. Preserving line breaks when saving and displaying custom fields data
  94. How to return Meta data from the REST API?
  95. Advanced Custom Fields – Get custom fields from parent page
  96. Can I query custom meta data through WP_Query
  97. Add custom field to the archive page?
  98. Saving custom data for each user
  99. Is it safe to store a user setting you don’t want the user to ever modify as a user option?
  100. Tabindex on text input immediately after WordPress title input
Categories custom-field Tags account, custom-field, woocommerce-offtopic
Show template part if part of term
Logout after clicking URL link results in “headers already sent” error

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