I am trying to figure out how to add variation to an existing product that is not an initially variable product.
So, I have a shirt with the goods, and I get one more of them in the warehouse in different colors, so my importer of the product needs to add a new version of this existing product.
wp_set_object_terms ($product_id, 'black', 'pa_color', 1);
$attr_data = Array(
'pa_color'=>Array(
'name' => 'pa_color',
'value' => '',
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1'
)
);
update_post_meta($product_id, '_product_attributes', $attr_data);
This adds color to my product, but destroys all my existing product attributes. Pulling the existing _product_attributes just gives me serialized attributes, so just adding a new option on top of everything doesn't work.
Any ideas?
source
share