in custom post type product of woocommerce, I have a some custom fields (created in ACF) and I need to take action when I save or update the post, that is, I want to add the values of the fields in woocommerce attributes. This is my example code. I have a text field called : ISBN , and I try to pass the value in meta attribute:
//save_post_NAME_CPT
add_action('save_post_product', 'update_post_meta_subito' , 10, 3 );
function update_post_meta_subito( $post_id, $post, $update ) {
//get field isbn of current post
$prova_termine = get_field( "isbn", $post_id );
//add value field in global pa_autore attribute
$term_taxonomy_ids = wp_set_object_terms( $post_id, $prova_termine, 'pa_autore', true );
//add value field in current attribute post
$data = Array(
'pa_autore'=>Array(
'name'=>'pa_autore',
'value'=>$prova_termine,
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1'
),
);
update_post_meta( $post_id, '_product_attributes',$data);
}
This not works! it does not pass any value! But in this case it works:
add_action('save_post_product', 'update_post_meta_subito' , 10, 3 );
function update_post_meta_subito( $post_id, $post, $update ) {
$prova_termine='ronaldo';
$term_taxonomy_ids = wp_set_object_terms( $post_id, $prova_termine, 'pa_autore', true );
$data = Array(
'pa_autore'=>Array(
'name'=>'pa_autore',
'value'=>$prova_termine,
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1'
),
);
update_post_meta( $post_id, '_product_attributes',$data);
}
So, in the first function does not take the value of the field, where am I wrong?