0

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.

1

try :

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.