Get customers using REST API
-
Hello,
this is the first time I trying to use Woocommerce REST API.
I’m reading the documentation.By using the following code, I’m able to get all customers:
<?php $api_url_users = 'https://mywebsite.com/wp-json/wc/v3/customers'; $api_key = "xxxxxx"; $api_secret = "xxxxxx"; // params $params = array( 'per_page' => 100, 'role' => 'all', ); // header $headers = array( 'Authorization: Basic ' . base64_encode($api_key . ':' . $api_secret) ); $url = $api_url_customers . '?' . http_build_query($params); // cURL options $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYPEER => true, )); // response $response = curl_exec($curl); curl_close($curl); // JSON decode $customers = json_decode($response, true);
It works! … but now I need to get all customers that has a specific meta_key empty. For example, if I need to get only customers that has postcode empty, in your opinion, is it possible?
I tried with something like that, but it doesn’t work:$params = array( 'per_page' => 100, 'role' => 'all', 'meta_query' => array( array( 'key' => 'postcode', 'value' => '', ), ), );
Maybe “search” param it can help me, but I can’t found any example for how to use search in REST API. I don’t know, maybe i had some confusion. Anyone can help me?
Thank you all.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Get customers using REST API’ is closed to new replies.