admin管理员组

文章数量:1122846

Is it possible to delete the global product attributes in WooCommerce by using WP-CLI?

I've often cleared out Users, Orders, and other items using something like this...

wp post delete $(wp post list --post_type='shop_order' --format=ids) --force

But I can't seem to find or figure out a good way to sort that for attributes.

I'm specifically referring to the attributes you configure under 'Products => Attributes' in the WordPress Dashboard not the ones that are added inline on products.

Is it possible to delete the global product attributes in WooCommerce by using WP-CLI?

I've often cleared out Users, Orders, and other items using something like this...

wp post delete $(wp post list --post_type='shop_order' --format=ids) --force

But I can't seem to find or figure out a good way to sort that for attributes.

I'm specifically referring to the attributes you configure under 'Products => Attributes' in the WordPress Dashboard not the ones that are added inline on products.

Share Improve this question asked Jun 27, 2024 at 18:05 fyrekcazfyrekcaz 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

本文标签: wp cliBulk delete 39Global Attributes39 in WooCommerce via WPCLI