Answer the question
In order to leave comments, you need to log in
Modifying responses in woocommerce rest api?
When rest request /wc/v3/products
throws out a huge json file with unnecessary fields.
How to make certain fields missing in the response from the server? Through functions.php or maybe something needs to be written in the request itself?
Something like this arrives:
But I want something like this:
Answer the question
In order to leave comments, you need to log in
in functions.php
add_filter( 'woocommerce_rest_prepare_product_object', 'filter_function_name', 10, 3 );
function filter_function_name( $response, $object, $request ){
if( empty( $response->data ) )
return $response;
$inclde = [
'id' => $response->data['id'],
'name' => $response->data['name'],
'images' => $response->data['images'],
'price' => $response->data['price'],
'meta_data' => $response->data['meta_data'],
'categories'=> $response->data['categories']
];
return $inclde;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question