Skip to content

Instantly share code, notes, and snippets.

@gabriserra
Created April 15, 2022 14:49
Show Gist options
  • Save gabriserra/6eae474656e24dc57369f6a7d3a8cdc2 to your computer and use it in GitHub Desktop.
Save gabriserra/6eae474656e24dc57369f6a7d3a8cdc2 to your computer and use it in GitHub Desktop.
#!/bin/bash
cd /var/www/wordpress
for site in $(wp site list --field=url)
do
echo "Checking" $site
wp wc --url=$site shop_coupon list --user=<your-admin-email> | grep <"coupon-code"> > /dev/null
if [ $? == "1" ]; then
echo "Not found. Creating ..."
wp wc --url=$site shop_coupon create \
--user=<your-admin-email> \
--code=<"coupon-code"> \
--amount=<amount> \
--discount_type="percent" \
--date_expires=<"yyyy-mm-dd">
else
echo "Already there!"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment