我在Woocommerce订单的屏幕上添加了一个新列,表明谁是订单的创建者(在该站点中,服务代表能够在后端为客户创建订单)。问题是当我搜索该数据时在订单屏幕上,我找不到任何。
订单的创建者设置为dd_post_meta()
的订单
所以我试过这样的事情:
function include_search( $query ) {
if ( is_admin() && $query->is_search() && $query->query['post_type'] == 'shop_order' ) {
$query->set( 'meta_query', array('key' => 'representative', 'value' => $query->query['s'], 'compare' => '=') );
}
}
add_action( 'pre_get_posts', 'include_search' );
但它不起作用。
例如,如果订单由“Ben X”创建,那么我可以看到他的名字出现在订单屏幕的右栏中,但是如果我在搜索框中搜索“Ben X”,我就不会找到那个订单。
对此有何帮助?
谢谢!
答案 0 :(得分:0)
如果有人需要帮助,我找到了答案:
function filter_woocommerce_shop_order_search_fields( $array ) {
$array[] = 'representative'; //The order meta key that needs to be include in the search
return $array;
};
add_filter( 'woocommerce_shop_order_search_fields', 'filter_woocommerce_shop_order_search_fields', 10, 1 );