Skip to content

Instantly share code, notes, and snippets.

@mustardBees
Created October 18, 2022 15:37
Show Gist options
  • Save mustardBees/bc8b548cb70bef5f8a4dd1146f7c82c5 to your computer and use it in GitHub Desktop.
Save mustardBees/bc8b548cb70bef5f8a4dd1146f7c82c5 to your computer and use it in GitHub Desktop.
WooCommerce WP-CLI/WC-CLI script to delete all products.
#!/bin/bash
# Save script, run chmod +x on it, then...
# Usage: ./delete_products.sh [user_id]
ARGS="$@"
COUNT=$(wp wc product list --user=$1 --format=count)
BATCHES=$(bc <<< "$COUNT/100+1")
echo "Deleting $COUNT products in $BATCHES batches (via user ID $1)"
for batch in $(seq $BATCHES)
do
echo "Batch $batch"
PRODUCTS=$(wp wc product list --user=$1 --field=id --format=csv --per_page=100)
for product in $PRODUCTS
do
wp wc product delete $product --user=$1 --force=true
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment