1

I tried to use the function given on this answer: Create programmatically a WooCommerce product variation with new attribute values

But i can't make it work, i inserted it on a my plugin function file instead of functions.php of my theme.

I call that function in this code after a product creation code:

    foreach ($variations as $variation) {

        $model_name = $variation['name'];
        $model_name = explode(',',$model_name);

        $color = $model_name[0];
        $model = $model_name[1];

        $price = $variation['price'];
        $stock = $variation['stock'];

        // The variation data
        $variation_data =  array(
            'attributes' => array(
                'color'  => $color,
                'model' => $model,
            ),
            'sku'           => '',
            'regular_price' => $price,
            'sale_price'    => '',
            'stock_qty'     => $stock,
        );

        // The function to be run
        create_product_variation( $new_post_id, $variation_data );

    }

All the values of product & variations came from a API call from external link. The data is on array format, i can get all those data i need, my problem now is to create the variations of the product and i used this create_product_variation but i cant make it work.

It gives me an error 500 status on my ajax call.

Ako Si
  • 101
  • 2
  • 8

0 Answers0