This question is related to a combination of WordPress plugins, which is why it belongs here and not on the WordPress stackexchange.
I asked the developers of ACF, but the told me that it was beyond the scope of their support.
I'm creating some products using the WooCommerce API, like this:
$data = [
'create' => [
[
'name' => 'Woo Single #1',
'type' => 'simple',
'regular_price' => '23.99',
'virtual' => false,
'downloadable' => false,
'meta_data' => [ // Example of creating a meta-field
[
'key' => 'repair_price',
'value' => 'asdfasdf'
]
]
]
],
'update' => [
[
'id' => 24357,
'meta_data' => [ // Example of updating a meta-field
[
'key' => 'repair_price',
'value' => 'asdfasdf'
]
]
],
]
];
$data_string = json_encode($data);
$ch = my_custom_setup_curl( https://my-site.com/wp-json/wc/v3/products/batch, 'POST', $data_string );
$result = json_decode( curl_exec($ch) );
$curl_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
After creating the products, I can see the custom field (repair_price) in the backend, since WooCommerce just creates a custom_field. But if I do this in the frontend:
$fields = get_fields();
echo '<pre>';
print_r($acf_fields);
echo '</pre>';
Then they don't show.
... But if I then just go the the newly created product and click 'Update' (after it has been created by the WooCommerce API, without changing anything) and then go back to the frontend, then the I can see the field.
I assume that it has something to do with the difference between update_post_meta() and update_field().
But how do I adjust the WooCommerce API, so custom fields created via that, will be accessible without having to do that extra save in the backend?
I'm going to create more than 1000+ products using the API, so the manuel process is not really an option.