Setting an attribute as variation in woo commerce via php [duplicate]

I got it working for my situation by using update_post_meta and wp_insert_post. Because I already setup my attributes and terms all I needed was a way to add to the above code so that when the product is created it not only will assign the attributes to the product but insert them as variations in the database.

Here is my solution:

//insert variations post_type
$i=1;
while ($i<=3) {
$my_post = array(
      'post_title'    => 'Variation #' . $i . ' of ' . esc_attr(strip_tags($_POST['postTitle'])),
      'post_name'     => 'product-' . $post_id . '-variation-' . $i,
      'post_status'   => 'publish',
      'post_parent'   => $post_id,
      'post_type'     => 'product_variation',
      'guid'          =>  home_url() . '/?product_variation=product-' . $post_id . '-variation-' . $i
    );

    // Insert the post into the database
    wp_insert_post( $my_post );

    $variable_id = $post_id + 1;
    $variable_two = $variable_id + 1;
    $variable_three = $variable_two + 1;

    update_post_meta( $variable_id, 'attribute_pa_resolution', 'high-resolution');
    update_post_meta( $variable_id, '_price', 8.50 );
    update_post_meta( $variable_id, '_regular_price', '8.50');

    update_post_meta( $variable_two, 'attribute_pa_resolution', 'medium-resolution');
    update_post_meta( $variable_two, '_price', 5.50 );
    update_post_meta( $variable_two, '_regular_price', '5.50');

    update_post_meta( $variable_three, 'attribute_pa_resolution', 'low-resolution');
    update_post_meta( $variable_three, '_price', 3.50 );
    update_post_meta( $variable_three, '_regular_price', '3.50');

    $i++;
    }