I'm using the Woocommerce REST API to automatically create product variations when a new product is added. The idea behind it, is that for every new product a variation for the paper size of the product needs to be added and the price calculated automatically using a specific formula. The creation of the different variations happens correctly. However the backend does not seem to select the variation correctly from the dropdown and still shows as "each variation" instead of the selected variation.
When viewing the details of a specific variation i do however see that all individual variations have been created correctly and the specific variation information has been added.
What i want to achieve is having the name of the attrbute as the selected option in the variation, but without any luck. Any advice on what I still need to add to achieve this? The code which handles the creation of the variations is as followed:
$taxonomy = 'pa_papiersoort';
$papers = get_terms( $taxonomy );
foreach( $papers as $single_paper ) {
$price = $this->calculate_price( $post->ID, $single_paper->name, 1 );
$data = [
'regular_price' => (string)$price,
'description' => $single_paper->name,
'attributes' => [
[
'name' => 'Papiersoort',
'slug' => 'papiersoort',
'option' => $single_paper->name
]
]
];
$woocommerce->post("products/$post->ID/variations", $data);
}