function append_text_to_product_title($title, $id) {
// Retrieve the text string to append
$text_to_append = ' - New Arrival';
// Append the text to the product title
$title .= $text_to_append;
return $title;
}
add_filter('woocommerce_product_title', 'append_text_to_product_title', 10, 2);
// Query the products
$products = new WP_Query(array(
'post_type' => 'product',
'posts_per_page' => -1
));
// Loop through the products
while ($products->have_posts()) {
$products->the_post();
// Get the current product ID
$product_id = get_the_ID();
// Get the current product title
$product_title = get_the_title();
// Append the text to the product title
$new_product_title = $product_title . ' - New Arrival';
// Update the product title
wp_update_post(array(
'ID' => $product_id,
'post_title' => $new_product_title
));
}
// Reset the query
wp_reset_query();
function append_text_to_product_title($title, $product) {
// Retrieve the text string to append
$text_to_append = ' - New Arrival';
// Append the text to the product title
$title .= $text_to_append;
return $title;
}
add_filter('woocommerce_product_get_title', 'append_text_to_product_title', 10, 2);
Метод 4. Прямое обновление базы данных
global $wpdb;
// Append the text to the product title in the database
$wpdb->query($wpdb->prepare("
UPDATE {$wpdb->prefix}posts
SET post_title = CONCAT(post_title, ' - New Arrival')
WHERE post_type = 'product'
"));