Woocommerce programmatically Add Attribute to Product

Viewed 48

I want to add the color attribute to all products in the X product category.

this is my code:

wp_set_object_terms( $productID, 'black', 'pa_color', true );

$att_color = Array('pa_color' =>Array(
       'name'=>'pa_color',
       'value'=>'black',
       'is_visible' => '1',
       'is_taxonomy' => '1'
     ));

update_post_meta( $productID, '_product_attributes', $att_color);

How can I do this? Someone can help me

0 Answers
Related