Skip to content

Instantly share code, notes, and snippets.

@phillcoxon
Forked from TimBHowe/functions.php
Created August 2, 2017 05:29
Show Gist options
  • 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;
}
@phillcoxon
Copy link
Author

Notes:

https://stackoverflow.com/questions/36369388/woocommerce-rest-api-custom-fields
https://stackoverflow.com/questions/39019579/custom-value-in-woocommerce-webhook-payload
https://stackoverflow.com/questions/40802219/woocommerce-rest-api-extending-order-response

Can we add BillingId: xxx (where xxx is the parent company id) to the CIN7 customer details so that all web store invoices get associated with the one Xero contact?

No idea if CIN7's delivery URL will actually receive BillingId but worth exploring

@reandimo
Copy link

Thaaanks

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