-
-
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
Thaaanks