Site icon Hip-Hop Website Design and Development

add action save post type and update post meta woocommerce

I want update post meta in product woocommerce when I save o update the product.
I write this function (and insert in functions.php) with save_post_NAME_CPT but don’t work.

    add_action('save_post_product', 'update_post_meta_subito', 10, 3 );

     function update_post_meta_subito($post_id){

       $post_type = get_post_type($post_id);


   $term_taxonomy_ids = wp_set_object_terms( $post_type, 'leopardi', 
      'pa_autore', true );

    $thedata = Array(

'pa_autore'=>Array( 
'name'=>'pa_autore', 
'value'=>'leopardi',
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1'
),


);


update_post_meta( $post_type, '_product_attributes',$thedata);

}