'Speed up woocomerce order admin search
I am using the following function to speed up woocommerce order admin search by searching in particular fields only:
function custom_woocommerce_shop_order_search_fields( $search_fields ) {
if(!empty($search_field = $_GET['searchfield'])) {
//not unsetting $search_fields because we will be returning it if none of the values match
// No need to pass search fields as order id searched by default
if($search_field === 'Order ID') {
return array();
}
if($search_field === 'Phone') {
return array('_billing_phone');
}
if($search_field === 'Email') {
return array('_billing_email');
}
if($search_field === 'Tracking Number') {
return array('_wcst_order_trackno');
}
}
//if some random value was passed, return array with number and mail, order id is searched by default
unset( $search_fields );
$search_fields[] = '_billing_phone';
$search_fields[] = '_billing_email';
return $search_fields;
}
add_filter( 'woocommerce_shop_order_search_fields', 'custom_woocommerce_shop_order_search_fields' );
I need to narrow it down further to search in orders that were created in past 1 year only and not beyond that to speed it up. How to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|