Created
May 23, 2023 10:36
-
-
Save craigpearson/a2d05ba4ab0a2d6b960d90dba0ec7b62 to your computer and use it in GitHub Desktop.
Output order data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# List all the site URLs | |
sites=$(wp site list --field=url) | |
# Loop over each site | |
for site in $sites | |
do | |
# Create a safe filename from the URL | |
filename=$(echo "$site" | sed 's/https\?:\/\///' | sed 's/\//_/g') | |
# Get a list of all order IDs | |
order_ids=$(wp --url="$site" post list --post_type='shop_order' --format=ids) | |
# Loop over each order | |
for order_id in $order_ids | |
do | |
# Get the order date | |
order_date=$(wp --url="$site" post get "$order_id" --field=post_date) | |
# Get the billing email | |
billing_email=$(wp --url="$site" post meta get "$order_id" '_billing_email') | |
# Append the data to the CSV file | |
echo "$billing_email,$order_date,$order_id" >> ~/"$filename.csv" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment