get_stock_quantity(); $parent = wp_get_post_parent_id( $product->get_id() ); $parent_product = wc_get_product( $parent ); $variations = $parent_product->get_available_variations(); foreach( $variations as $variation ){ //Must set directly to custom field, $product->set_stock_quantity() call this loop again for each variation and stock is set by last variation qty $variation_product = update_post_meta( $variation['variation_id'], '_stock', $qty ); } }