I have a form which makes people decide about the sub-categories of their product and the form gets submitted on user post method
Im trying to add the parent category to it as well
Now I tested couple of way to adding the $term
but each time it just get replaced not added
add_action('transition_post_status', 'new_product_add', 10, 3);
function new_product_add($new_status, $old_status, $post) {
if(
$old_status != 'publish'
&& $new_status == 'pending'
&& !empty($post->ID)
&& in_array( $post->post_type,
array( 'product')
)
) {
$term = get_term_by('name', 'parent_category', 'product_cat');
wp_set_object_terms($post->ID, $term->term_id, 'product_cat');
}
}