是否可以将文本添加到"描述";Woommerce rest API响应中的字段?
使用函数add_filter
向the_content
添加文本似乎不会影响API响应,只会影响前端渲染。
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;
}