add action save post type and update post meta woocommerce

admin2025-01-07  4

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

}

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

}

Share Improve this question asked Oct 23, 2018 at 17:21 Antonio CarboneAntonio Carbone 216 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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);

}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736256621a374.html

最新回复(0)