How can I replace the values in WP_Term?

To replace values in a WP_Term object, you can modify its properties directly. For example:

$term = get_term( $term_id, $taxonomy );

if ( ! empty( $term ) && ! is_wp_error( $term ) ) {
    $term->name="New Term Name";
    $term->slug = 'new-term-slug';
    $term->description = 'New Term Description';
}

In this example, the get_term() function is used to retrieve a WP_Term object based on the term ID and taxonomy. If the term is found and is not an error, its properties name, slug, and description are updated with new values.

Note that after updating the properties, you need to use the wp_update_term() function to persist the changes in the database:

$update_result = wp_update_term( $term->term_id, $taxonomy, array(
    'name' => $term->name,
    'slug' => $term->slug,
    'description' => $term->description,
) );

if ( is_wp_error( $update_result ) ) {
    // error updating term
} else {
    // term updated successfully
}