I
I
itmalex2020-06-05 18:58:39
WordPress
itmalex, 2020-06-05 18:58:39

How to programmatically update a product attribute?

Unable to update product attribute normally. Tried a lot of options, it doesn't work.

$product = new WC_Product_Simple(39587);
    $attribute = new WC_Product_Attribute();
    $attribute->set_id(0);
    $attribute->set_name("pa_size");
    $attribute->set_options([1689]); //id атрибута
    $attribute->set_position(0);
    $attribute->set_visible(1);
    $attribute->set_variation(0);
    $attributes["pa_size"] = $attribute;

    $product->set_attributes($attributes);


After running the script, I get:
5eda6a20e0823121077605.png

If you click the save button, everything is normal, but I need to do it from the plugin.

Expect:
5eda6b2646537953589204.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question