Is it possible to add text to the "description" field in a Woocommerce rest API response?
Adding text to the_content
using function add_filter
does not seem to affect the API response, only the frontend render.
CodePudding user response:
add_filter( 'woocommerce_rest_prepare_product_object', 'add_custom_text_to_product_descr', 10, 3 );
function add_custom_text_to_product_descr( $response, $order, $request ) {
if ( empty( $response->data ) ) {
return $response;
}
$custom_text = 'This text was appended using the woocommerce_rest_prepare_product_object hook.';
$response->data['description'] .= $custom_text;
return $response;
}