我使用Wordpress API从WooCommerce检索订单。 Wordpress和Woo是最新的。检索通过“ / wp-json / wc / v3 / orders”进行。
现在,我想通过自定义字段(也在“ meta_data”下方显示)过滤对这些订单的检索。不幸的是,自定义字段不能用作获取参数。参数“?filter”一段时间不可用。我不想使用将它带回来的插件。
您能告诉我我必须使用哪个挂钩来将自定义字段(或特殊自定义字段)用作过滤器属性吗?
使用此代码,我设法限制了具有自定义字段的页面。我需要同样的WooCommerce订单。不幸的是,当我使用“ add_filter('rest_shop_order_query','post_meta_request_params',99,2)“时,此代码不起作用。
if( ! function_exists( 'post_meta_request_params' ) ) :
function post_meta_request_params( $args, $request )
{
$args += array(
'meta_key' => $request['meta_key'],
'meta_value' => $request['meta_value'],
'meta_query' => $request['meta_query'],
);
return $args;
}
add_filter( 'rest_post_query', 'post_meta_request_params', 99, 2 );
endif;