I would like to get the order history for 25k customers. I have each of the customer's email address. My current pipeline is to loop through the email addresses, get the corresponding customer, then get the orders corresponding to that customer.

I'd like to speed this up through one or both of the following:

1) Getting the customers from emails in batches, rather than one at a time

2) Going directly from customer email to list of orders.

How can either of these be accomplished? Is there a better way to accomplish my goal that I am overlooking?

Edit: My current (working but slow) code:

import json
from woocommerce import API

with open("credentials/woocommerce_api_keys.json",'r') as f:
    woo_credentials = json.load(f)

wcapi = API(

with open("customer_emails.csv",'r') as f:
    customer_emails = f.read().split(",")
customers = []
orders_by_customer = {}
order_dates_by_customer = {}
for email in customer_emails:
    customer = wcapi.get("customers/?email={}".format(email)).json()
    if len(customer) == 1:
        customer = customer[0]
        customer_id = customer["id"]
        orders = wcapi.get("orders/?customer={}".format(customer_id)).json()
        orders_by_customer[email] = orders
        order_dates = []
        for o in orders:
        order_dates_by_customer[email] = order_dates
        print("email {} returns {} customers".format(email,len(customer)))

with open("data/customers.json",'w') as f:
with open("data/orders_by_customer.json",'w') as f:
with open("data/order_dates_by_customer.json","w") as f:

You need to implement the loop for all the emails you have in your database. then for each you can use below code: $exists = email_exists($email); if ( $exists ) echo "That E-mail is registered to user number "; else echo "That E-mail doesn't belong to any registered users on this site";

If you are facing issue please share more details on your question

  • Thanks for the reply. I already have a working implementation that loops through the emails (I added the code to my question). I want to know how to speed this process up. Sorry for making my question unclear. – Michael Fishman Oct 7 '19 at 17:43
  • Is it ajax call or JS call? – Pratikb.Simform Oct 9 '19 at 7:51

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.