Метод 1: использование фильтра «woocommerce_product_title»
function append_text_to_product_title($title, $id) {
// Append the desired text string to the product title
$title .= ' - Additional Text';
return $title;
}
add_filter('woocommerce_product_title', 'append_text_to_product_title', 10, 2);
Метод 2. Изменение названия продукта непосредственно в файле шаблона
function modify_product_title() {
global $product;
// Get the current product title
$title = $product->get_title();
// Append the desired text string to the product title
$title .= ' - Additional Text';
// Output the modified title
echo $title;
}
add_action('woocommerce_single_product_summary', 'modify_product_title', 6);
Метод 3. Использование JavaScript/jQuery для изменения названия продукта во внешнем интерфейсе
jQuery(document).ready(function($) {
// Get the product title element
var $productTitle = $('.product_title');
// Append the desired text string to the product title
$productTitle.text($productTitle.text() + ' - Additional Text');
});
Эти методы позволяют добавлять текстовую строку к названию отдельного продукта WooCommerce разными способами.