Couldn't add multiple attribute variations programmatically
-
Hi,
I am trying to add simple and variable product programmatically. I have done with simple product but facing a single problem in variable product. I have size attribute and 3 variations XL,L,S. But when i submit my product form , it creates 3 variations but only one selected i-e the first one XL. remaining unselected.
$new_product_id = wp_insert_post($post, $wp_error); $avail_attributes = get_terms(wc_attribute_taxonomy_name('size'), $args_t); $x = 1; $amount = 350; foreach ($avail_attributes as $attr) { $my_postt = array( 'post_title' => 'Size ' . $attr . ' for #' . $new_product_id, 'post_name' => 'product-' . $new_product_id . '-variation-' . $x, 'post_status' => 'publish', 'post_parent' => $new_product_id, 'post_type' => 'product_variation', 'guid' => home_url() . '/product_variation/product-' . $new_product_id . '-variation-' . $x ); $attID = wp_insert_post($my_postt); update_post_meta($attID, 'attribute_pa_size', $attr); update_post_meta($attID, '_price', $amount); update_post_meta($attID, '_regular_price', $amount); $x++; $amount-=50; //die("test"); }
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Couldn't add multiple attribute variations programmatically’ is closed to new replies.