使用当前的Woocommerce文档,我可以从网站上的woocommerce检索所有订单。
"line_items" => array:2 [▼
0 => array:14 [▼
"id" => 1
"name" => "Multi Tool"
"product_id" => 227
"variation_id" => 0
"quantity" => 1
"tax_class" => ""
"subtotal" => "15.00"
"subtotal_tax" => "0.00"
"total" => "15.00"
"total_tax" => "0.00"
"taxes" => []
"meta_data" => []
"sku" => ""
"price" => 15
]
1 => array:14 [▶]
问题是,api没有为每个产品提供类别,它只响应line_items下的product_ id。有没有我可以在每个产品下添加一个自定义字段,名为类别,每个产品的类别名称?
答案 0 :(得分:0)
您必须使用以下过滤器更改Orders API的响应。
add_filter( 'woocommerce_rest_prepare_shop_order_object',
'custom_change_shop_order_response', 20, 3 );
function custom_change_shop_order_response( $response, $object, $request ) {
//here you can customize the product response of the order
}