Codexshaper / laravel-woocommerce

WooCommerce Rest API for Laravel
MIT License
198 stars 57 forks source link

Query the orders related to a customer? #94

Open Darpan-laravel opened 2 years ago

Darpan-laravel commented 2 years ago

Hi, I was trying to query orders related to a specific customer. But what I have found is that, in order fields received through order api, in the billing section under it, there is an email field under billing which matches with the email field of the customer fields received through customer api and THIS IS THE ONLY LINK. There is a 'customer_id' field in the order params but most of the times it is 0 (I believe 0 is for guests in WooCommerce?). [Moreover, the billing field you get is in the format (in order api), [ { "id": 7337, //order_id "billing": { "email": "cuccagna@gmail.com", }, } ]

So, I am trying the below query on the basis of the results I got, (I am using the data received through api directly, not saving those in database)

$customeremail = $request->email; $order_of_the_customer = order:where('to->billing->email', $customeremail)->get(); Or, $order_of_the_customer = order::whereJsonContains('to', [['billing' => ['email' => $customeremail ]]])->get();

But NONE OF THESE WORKS!!. Can someone help me? Seems like no queries using where condition is working.. (even simple queries, it always results in all the results (which is 10 per page)) (only order::find($id) works efficiently)

Darpan-laravel commented 2 years ago

Anyone here has found any way to fetch the orders related to a particular customer ?