I am looking for a way to extend wc-api / vX / orders / reponse. I added some special fields for checking (for example, relationship number, delivery date, etc.). These meta are stored in order (wp_postmeta table). But why don't they return using api?
You can usually extend the api response with some code:
add_action( 'rest_api_init', 'custom_register_api_fields' );
function custom_register_api_fields() {
register_rest_field( 'shop_order','relation_number',
array(
'get_callback' => 'custom_api_meta_callback',
'update_callback' => null,
'schema' => null,
)
);
}
function custom_api_meta_callback( $object, $field_name, $request ) {
return get_post_meta( $object[ 'id' ], $field_name, true );
}
But when I test the answer (with Postman and php lib), my-website.co/wc-api/v2/orders user meta is not visible.
Is there any way to register api fields for wc-api?
Tnx!
source
share