0

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);

}

0

I solved:

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

function update_post_meta_subito($post_id){

    $prova_termine='inzaghi';


    $term_taxonomy_ids = wp_set_object_terms( $post_id, $prova_termine, 'pa_autore', true );

    $thedata = 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',$thedata);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.