0

I am using the following code to limit the fields that woocommerce searches in when you search for an order:

/**
* Limit woocommerce order search fields. 
*/
function custom_woocommerce_shop_order_search_fields( $search_fields ) {

    // error_log( 'currently searching in these order fields: ' . print_r($search_fields, true) );
    unset( $search_fields );
    $search_fields[] = '_order_key';
    $search_fields[] = '_billing_company';
    $search_fields[] = '_billing_email';

    // error_log( 'now only searching in these order fields: ' . print_r($search_fields, true) );
    return $search_fields;

}
add_filter( 'woocommerce_shop_order_search_fields', 'custom_woocommerce_shop_order_search_fields' );

This limits the search fields to Order ID, company and email only, speeding up order search. I need to have a dropdown along with the search field which will have Order ID, Billing Company, Billing Email as values. If we select Order ID, then the search should happen in Order IDs(_order_key) only, if we select Billing Company, then the search should happen in Billing Company(_billing_company) field only and so on. How to add this dropdown along with order search?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.