Woocommerce REST API: creating variations

This took me a while but i’ve been able to solve this issue through writing in the database directly so i’d share my solution here for others if anyone comes across the same problem.

To get the attributes selected automatically when creating the variations, 2 things need to happen in the database. The variation post title needs to be adjusted in the form of “product-name variation-name”. The second part is adding a new postmeta with the key “attribute_pa_taxonomy” and the meta value being the slug of the selected attribute.

Changing these 2 things in the database directly will assign the selected attribute correctly in the backend overview.

$wpdb->query("UPDATE {$wpdb->prefix}posts SET post_title="$product->name $single_paper" WHERE ID = $id");
$wpdb->query("INSERT INTO {$wpdb->prefix}postmeta(`post_id`, `meta_key`, 
`meta_value`) VALUES ('$id', 'attribute_pa_papiersoort', '$slug')");