Skip to content

Instantly share code, notes, and snippets.

@phillcoxon
Forked from TimBHowe/functions.php
Created August 2, 2017 05:29
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phillcoxon/11a430c58460b147941cd6833ac36571 to your computer and use it in GitHub Desktop.
Save phillcoxon/11a430c58460b147941cd6833ac36571 to your computer and use it in GitHub Desktop.
WooCommerce - Add custom post_meta data to the order REST API response.
<?php
/**
* Hook into order API response to add custom field data.
*
* @param $order_data array
* @param $order WC_Order
* @param $fields array
* @param $server array
*
* @return $order_data array
*/
add_filter( 'woocommerce_api_order_response', 'add_foo_field_order_api_response', 20, 4 );
function add_foo_field_order_api_response( $order_data, $order, $fields, $server ) {
// Get the custom order post_meta data and add it to the order_data array.
$order_data['foo'] = get_post_meta( $order->id, 'foo', true );
return $order_data;
}
@reandimo
Copy link

Thaaanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment