1

I have some custom attributes for each product in woocommerce, I can edit them at the Attributes tab. I can also read them using this code

$product = new WC_Product($product_id);
$v = $product->get_attribute('myattr_name');

But I don't understand how to set this attribute value. Googling not helps. Do you know? I am looking for something like this

$product->set_attribute('myattr_name', $new_value);

But as I can see, there is no such method.

  • it's a simple or a variable product ? – mmm Mar 21 '18 at 21:25
  • @mmm A simple one – Epsiloncool Mar 21 '18 at 21:48
  • 2
    try with that : $product->set_props(["attributes" => ["myattr_name" => $new_value]]); $product->save(); – mmm Mar 21 '18 at 21:52

Your Answer

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

Browse other questions tagged or ask your own question.