3

I'm looking to mass remove or clear the default attribute for variable products in Woocommerce.

enter image description here

Is there an easy way to mass clear this value? If not, would you be able to direct me on where I can find this value in phpMyAdmin?

2 Answers 2

2

Default attributes of WooCommerce variable products are stored as post meta in the database. You can find them in the wp_postmeta table, where the post_id column is the post ID of the parent product (Variable product), and the meta_key column is _default_attributes.

You can clear and remove default attributes of all products by replacing all non-empty arrays.

To do so, open phpMyAdmin and select the database of your WordPress installation from the left panel and click on SQL tab. Then write the below SQL commands and press Go:

Don't forget to backing up your database before executing any command on phpMyAdmin

UPDATE `wp_postmeta` SET `meta_value`= 'a:0:{}' WHERE meta_key = '_default_attributes'
1
  • How can I change ALL products to have the attribute "fabric" by default?
    – FilipeOS
    Mar 30, 2020 at 14:07
1

you can modify the default attribute with the following code. this code retrieve the complet list of products then it can use a big amount of ressources

$products = wc_get_products([
    "nopaging" => TRUE, // retrieve all products
]);


foreach ($products as $p) { 

    $default_attributes = $p->get_default_attributes();

    if (    (!empty($default_attributes))
        &&  FALSE // other condition to select of which product the default attributes is reset
    ) {

        $p->set_default_attributes("");

    }


}
2
  • Any particular place to run this code from?
    – Humble Val
    Mar 30, 2018 at 6:39
  • in your function.php in your theme folder Apr 2, 2018 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.