I’m looking for a way to search to make wordpress search for matches on a WC users billing-/shipping-company – but im not sure how to achive this.
I found out how i can do it with the most common user fields (ID, login, email & nicename).

Searching for common user data:

    $customers_query = new WP_User_Query( apply_filters( 'woocommerce_json_search_customers_query', array(
        'fields'         => 'all',
        'orderby'        => 'display_name',
        'search'         => '*' . $term . '*',
        'search_columns' => array( 'ID', 'user_login', 'user_email', 'user_nicename')
    ) ) );   

I tried also tried:

    $yoursearchquery = 'Andr';
    $users = new WP_User_Query(array(
        'search' => $yoursearchquery,
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => 'billing_last_name',
                'value' => $yoursearchquery,
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'billing_first_name',
                'value' => $yoursearchquery,
                'compare' => 'LIKE'
            )
        )
    ));

but this only returns if i use the EXACT word i want it to search for – and not part of the word.

Read more here: Search users with custom meta data


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: