My problem was briefly the same -hundreds of products, which numbers are continuously increasing- and didn't find any feasable code based solution, also Woocommerce documentation looks intentionally outdated.
Long story short: Use built-in WooCommerce Product CSV Importer and Exporter tool to achieve this goal. Makes things way simpler and faster in the long run. Although Woocommerce states the following:
In the long term, this extension will be phased out... source
Would be logical to just refer to variation id, when it comes to selecting the default one for each product, right? For some reason it was implemented differently...
I'll guide you through an example, which already includes some variable products and their variations. Here's an example
Export your products or create a CSV UTF-8 sheet based on parameters available in Woocommerce documentation. Here
Add the following columns with their respective number as:
| Attribute 1 default | Attribute 2 default |
|---|
Attribute related header titles in order in this example:
| Type | SKU | Name | Visibility in catalogue | Tax class | In stock? | Stock | Regular | price | Parent | Attribute 1 name | Attribute 1 value(s) | Attribute 1 visible | Attribute 1 global | Attribute 1 default | Attribute 2 name | Attribute 2 value(s) | Attribute 2 visible | Attribute 2 global | Attribute 2 default |
|---|
Since it's a plain text database, you can let your excel skills push the limit of this method, and save load of time by using formulas, just like me or even better: scripting the whole process.