Created
October 18, 2022 15:37
-
-
Save mustardBees/bc8b548cb70bef5f8a4dd1146f7c82c5 to your computer and use it in GitHub Desktop.
WooCommerce WP-CLI/WC-CLI script to delete all products.
This file contains 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 | |
# 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