• Resolved ashishtheword

    (@ashishtheword)


    Hello there,

    I was trying to create a variable product using the API Method WC_Product_Variable Class in my store for that we are using set_attributes method for creating the attributes and set_variation_attribute for creating the variation in WooCommerce here is the code which we are using:

    $products = new WC_Product_Variable();//$wcProductID
    $products->set_name(‘Test Product Config For True color123’);
    $products->set_sku(‘testconfig’);
    $products->set_regular_price(200);
    $products->set_sale_price(180);
    $products->set_attributes($product_array);
    $products->set_variation_attributes(array(
    array(
    ‘sku’ => ‘codered’,
    ‘regular_price’ => ‘29.98’,
    ‘attributes’ => array(
    array(
    ‘name’=>’color’,
    ‘options’=>’red’
    )

    )
    ),
    array(
    ‘sku’ => ‘codeblack’,
    ‘regular_price’ => ‘29.98’,
    ‘attributes’ => array(
    array(
    ‘name’=>’color’,
    ‘options’=>’black’
    )
    )
    )
    ));
    $result=$products->save();

    By this a Variable Product gets created successfully, but without any attribute and variables. Please we need your help in creating the Variable Product in WooCommerce. Please response ASAP.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Create Variable Product Using the WC_Product_Variable() Class’ is closed to new replies.