laravel-woocommerce icon indicating copy to clipboard operation
laravel-woocommerce copied to clipboard

Query the orders related to a customer?

Open Darpan-laravel opened this issue 3 years ago • 1 comments

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": "[email protected]", }, } ]

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 avatar Oct 26 '22 08:10 Darpan-laravel

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

Darpan-laravel avatar Nov 03 '22 09:11 Darpan-laravel