• Resolved Cezar Ayran

    (@ayrancd)


    I’m creating a variable product and to set the attribute I have the following code that works just fine:

    $attribute = new WC_Product_Attribute();
    $attribute->set_id(0);
    $attribute->set_name('Group 1');
    $attribute->set_options(array('Blue', 'Green', 'Red'));
    $attribute->set_position(0);
    $attribute->set_visible(0);
    $attribute->set_variation(1);
    
    $product->set_attributes(array($attribute));

    How do I add more than one Name and Options? So like Group 2 and its options: A, B, C… just need to understand the syntax of how I can add multiple attributes. Thanks!!!

Viewing 1 replies (of 1 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @ayrancd,

    To add more than one attribute, you will need to create multiple instances of WC_Product_Attribute() and add them to the attributes array.

    Please note that writing or providing custom code is not within the scope of our support policy. If you still need assistance, we recommend asking development questions on the #developers channel of the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

Viewing 1 replies (of 1 total)
  • The topic ‘Add multiple attributes’ is closed to new replies.