Bulk delete ‘Global Attributes’ in WooCommerce via WP-CLI?

As we know WooCommerce product attributes are stored in a custom taxonomy, It means we need to work with taxonomies and terms instead of posts. WP-CLI provides commands for working with taxonomies and terms that can be used for this purpose.

We are going to follow the given steps:
List all global product attributes > Delete all terms in each global attribute taxonomy

We will use the given CLI to list out all taxonomies so we can identify our attribute taxonomies.

wp taxonomy list --format=json | jq '.[] | select(.name | startswith("pa_"))'

We will use given CLI to delete all terms we have in a specific taxonomy.

wp term list pa_color --field=term_id | xargs wp term delete pa_color

Here we need to replace pa_color with the actual taxonomy you want to delete terms from.

tech