2

i want to create a function which will add to specific products an attribute programmatically. i use the below code but it doesnt seem to work.

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

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

if i set taxonomy to 0 the attribute is passed to the product but it doesnt appear in the front end unless i press update manually to each product. what can i do to add attributes to product? i want to mention that the products are simple products not variable.

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

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

update_post_meta( $productID, '_product_attributes', $att_color);
  • its Work's for me you can try this – vikas Rana Apr 3 at 13:40
  • Please edit your answer, and add an explanation: why could that solve the problem? – fuxia Apr 3 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.