Update all variations prices of a variable product in Woocommerce

Viewed 7495

I need to get all variation id and update price in loop. Simple query and loop looks like:

$params = array(
  ‘posts_per_page’ => -1,
  ‘post_type’ => ‘product_variation’,
  ‘post_parent’ => $product->get_id() // tried $post-ID
);
$variations = get_posts( $params );
foreach ( $variations as $variation ) {
  $variation_ID = $variation->ID; // tried $post-ID, $product->get_id()
  $regular_price=34;
  update_post_meta( $variation_ID, ‘_regular_price’, (float)$regular_price );
  update_post_meta( $variation_ID, ‘_price’, (float)$regular_price );
}

I think not working this:

(‘post_parent’ => $product->get_id()) 

or this:

($variation_ID = $variation->ID;). 
1 Answers
Related