-
-
Save phillcoxon/11a430c58460b147941cd6833ac36571 to your computer and use it in GitHub Desktop.
WooCommerce - Add custom post_meta data to the order REST API response.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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