Skip to content

Instantly share code, notes, and snippets.

@luelista
Last active July 24, 2020 12:15
Show Gist options
  • Save luelista/a21a5a141a2ddfb7a05842aa2db2e538 to your computer and use it in GitHub Desktop.
Save luelista/a21a5a141a2ddfb7a05842aa2db2e538 to your computer and use it in GitHub Desktop.
List and update the download URL of all downloadable files of virtual products in a WooCommerce installation
(wp post list --post_type=product_variation --meta_key=_downloadable_files --fields=ID | tail -n +2;
wp post list --post_type=product --meta_key=_downloadable_files --fields=ID | tail -n +2) | (
while read ID; do wp post meta get $ID _downloadable_files ; done)
# replaces the host "test.ugb-verlag.de" with "ugb-verlag.de" in all download URLs
(
wp post list --post_type=product_variation --meta_key=_downloadable_files --fields=ID | tail -n +2;
wp post list --post_type=product --meta_key=_downloadable_files --fields=ID | tail -n +2) | (
while read ID; do
wp post meta get $ID _downloadable_files --format=json | \
jq '.[].file |= (. | sub("test.ugb-verlag.de"; "ugb-verlag.de"))' | \
wp post meta update $ID _downloadable_files --format=json
done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment