• Resolved peefy

    (@peefy)


    any idea how to delete all my product categories? via wp/wc-cli or another method (wp-cli, plugin, sql, php) ?
    I am using latest woocommerce v4.2.1

    I tried this:

    $ wp wc product_attribute delete $( wp wc product_attribute list –format=ids –user=”contact” ) –force
    Error: Too many positional arguments: 45 24 77 73 78 75 76 74 29 68 23 22 27 71 19 72 20 53 60 41 40 37 67 28 58 46 56 32 25 39 44 61 62 70 64 35 52 66 47 50 63 38 59 36 69 43 21 33 57 54

    but it is not working as the delete command here apparantly only accepts 1 argument

    Any ideas how to solve this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @peefy!

    If you want to delete all your product attributes, you can use the following SQL query and run this directly in phpmyadmin:

    DELETE FROM wp_terms WHERE term_id IN
    (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%');
    DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%';
    DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN
    (SELECT term_taxonomy_id FROM wp_term_taxonomy);

    Cheers!

    Thread Starter peefy

    (@peefy)

    Hi Rynaldos,
    Thank you for your answer.
    I found your code snipet earlier on an old post from 2015:
    https://melissafreeman.com.au/wordpress-bulk-remove-woocommerce-products-attributes-sql-commands/

    but the comments state that the table structure has changed since, e.g. woocommerce_attribute_taxonomies table is added etc.

    user mansi says there: “I just had to do additional delete queries after this to support latest WooCommerce version. Latest WC stores attributes at another custom table ‘woocommerce_attribute_taxonomies’. It will be great if you can add that part in your article to make it complete for latest WC.”

    Can you give an updated version that is up to date to version 4.x please?
    Thank you very much!

    Thread Starter peefy

    (@peefy)

    Anyone having an answer?

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @peefy I cannot think of an answer for this other than going to the Products> Attributes page and using the bulk actions to delete the attributes. This is the way I’ve cleared out my test sites for years. If you increase the number of items under Screen Options to 100, you can clear out 1000 in just a couple minutes.

    @jessepearson

    Theres no bulk actions available for product attributes. You can only edit one item at a time.

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @janekkrause You’re correct. I thought I had double checked before answering, I must have clicked on Tags or into the terms for an Attribute.

    Create a file on the website root directory and use this code

    <?php
    include 'wp-load.php';
    
    $attributes = json_decode(json_encode(wc_get_attribute_taxonomies()),true);
    sort($attributes);
    
    foreach ($attributes as $key => $attribute) {
        $deleted = wc_delete_attribute( $attribute['attribute_id'] );
        echo '<pre>';
        print_r(sprintf('Deleting %s - Result %s',$attribute['attribute_label'], $deleted));
        echo '</pre>';
        
        
        
       
    }
    Thread Starter peefy

    (@peefy)

    thank you all!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘how to delete all product attributes?’ is closed to new replies.