I am create an wordpress plugin for an API. I am getting products, and for each product I get and array of attributes with name and value. I have tried something but it doesn't appear to be doing anything.
foreach($product->attributes as $attribute) {
$slug = 'pa_' . strtolower($attribute->name);
$attribute_value = $attribute->value;
$thedata = [
$slug => [
'name'=> $slug,
'value'=> $attribute_value,
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1'
]
];
update_post_meta( $product_id, '_product_attributes', $thedata);
}
My guess is that i have to search ( or add if doesn't exist ) and attribute, then do the same thing for the value. I am not sure.
Facts: - Everything else in the script works, and yes - the $product comes and also the $product_id hold the id of the product that was created a bit above in the script.