我想更新后元在产品woocommerce时,我保存更新产品。我用save\\u post\\u NAME\\u CPT编写这个函数(并在functions.php中插入),但不起作用。
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);
}
SO网友:Antonio Carbone
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);
}