-2

I am using WooCommerce and I need some help. How to extend search functionality to the customer phone number in the admin WooCommerce orders list?

This is my code actually.

function woocommerce_shop_order_search_custom_keys( $search_fields ) {
    $search_fields[] = '_order_number';
    $search_fields[] = '_billing_phone';
    $search_fields[] = '_billing_id';
    return $search_fields;

} 

But is not working


EDIT: I have also tried to add this to my code without any success:

add_filter( 'woocommerce_shop_order_search_fields', 'woocommerce_shop_order_search_custom_keys' ); 
8
  • How are you calling this function? On some hooks ? This functions alone does not gives any idea. Commented Aug 24, 2017 at 6:41
  • yes , i don't have idea how can i call the how to search Commented Aug 24, 2017 at 6:43
  • just now i added the line Commented Aug 24, 2017 at 6:44
  • add_filter( 'woocommerce_shop_order_search_fields', 'woocommerce_shop_order_search_custom_keys' ); this way i called Commented Aug 24, 2017 at 6:44
  • but not working Commented Aug 24, 2017 at 6:44

1 Answer 1

3

The correct way to get the billing phone as in the orders list search field within a custom function hooked in woocommerce_shop_order_search_fields filter hook is:

add_filter( 'woocommerce_shop_order_search_fields', 'billing_phone_search_fields', 10, 1 );
function billing_phone_search_fields( $meta_keys ){
    $meta_keys[] = '_billing_phone';
    return $meta_keys;
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested on WooCommerce 3+ and works.

Sign up to request clarification or add additional context in comments.

1 Comment

I have applied your coed but i have doubt when i search phone the parameter name ? this is my web services URL: localhost:8080/iconnect/public/api/v1/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.