Please add the below code snippet in your child theme’s functions.php file in order to get the custom field values through API
add_filter('woocommerce_rest_prepare_shop_order_object', 'filter_order_response', 10, 3); function filter_order_response($response, $post, $request){ // Customize response data here $order_id = $post->get_id(); $value = ( $value = get_post_meta($order_id, 'field_name', true) ) ? $value : ''; $response->data['billing']['field_name'] = $value; return $response; }
Please note that when an order is placed the field values are saved as billing_’field name’ and shipping_’field name’ in order meta. So please provide the field name accordingly.
Thank you!
As a follow-up, please add the below code snippet in your child theme’s functions.php file in order to get the custom field values through API
add_filter('woocommerce_rest_prepare_shop_order_object', 'filter_order_response', 10, 3);
function filter_order_response($response, $post, $request){
// Customize response data here
$order_id = $post->get_id();
$value = ( $value = get_post_meta($order_id, 'field_name', true) ) ? $value : '';
$response->data['billing']['field_name'] = $value;
return $response;
}
Please note that when an order is placed the field values are saved as billing_’field name’ and shipping_’field name’ in order meta. So please provide the field name accordingly.
Thank you!
Hi.
I’m having trouble with this piece of code. After following the steps and replacing the field name, I just get an empty field information in Make.com. The custom name field is “numerodoc”, and thus this is the code I’m using:
add_filter('woocommerce_rest_prepare_shop_order_object', 'filter_order_response', 10, 3);
function filter_order_response($response, $post, $request){
$order_id = $post->get_id();
$value = ( $value = get_post_meta($order_id, 'numerodoc', true) ) ? $value : '';
$response->data['billing']['numerodoc'] = $value;
return $response;
}
Ideally, we would need to fetch in Make.com the data of 3 different custom fields: billing_tipodoc, billing_numerodoc and billing_email_facturas. I tried with this code, and again I’m getting empty data in Make.com (I’m not an expert, and this was made with the help of ChatGPT):
add_filter('woocommerce_rest_prepare_shop_order_object', 'filter_order_response', 10, 3);
function filter_order_response($response, $post, $request) {
// Customize response data here
$order_id = $post->get_id();
// Get the value of 'email_facturas'
$value1 = ( $value1 = get_post_meta($order_id, 'email_facturas', true) ) ? $value1 : '';
$response->data['billing']['email_facturas'] = $value1;
// Get the value of 'tipodoc'
$value2 = ( $value2 = get_post_meta($order_id, 'tipodoc', true) ) ? $value2 : '';
$response->data['billing']['tipodoc'] = $value2;
// Get the value of 'numerodoc'
$value3 = ( $value3 = get_post_meta($order_id, 'numerodoc', true) ) ? $value3 : '';
$response->data['billing']['numerodoc'] = $value3;
return $response;
}
I really appreciate your help!