Setting WooCommerce SKU programmatically [closed]

You should use save_post hook. Try the code below:

function wpse_304031_save_post( $post_id, $post ) {

    // return if autosave
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return;
    }

    $your_sku = 'Custom SKU for ' . $post->post_title;

    if( $post->post_type == 'product' ) {
        if( empty( get_post_meta( $post_id, '_sku', true ) ) ) {
            update_post_meta( $post_id, '_sku', $your_sku );
        }
    }

}

add_action( 'save_post', 'wpse_304031_save_post' );

Here I’m using title of the product to build sku. You can use anything you want.