Issues with translating checkout fields
-
Hello,
I have a custom .php script which forces translating cyrilic letters to latin.
I have website on Serbian and Russian and I want complete website to be on latin.
Script worked before.
After update I noticed that some fields in checkout page are not on latin any more.
1. Стан, апартман, локал итд.
2. Град?*
3. Округ?*
4. All regions in Serbian are also on cyrilic
What is changed and how to fix it?
I checked with theme support, they claim that this is not theme releated, but probably that something in WooCommerce is changed.
Im sharing my current script which worked before.// Function for transliteration from Cyrillic to Latin within entire HTML content
function cir_to_lat($text) {
$cirilica = array(
'А', 'Б', 'В', 'Г', 'Д', '?', 'Е', 'Ж', 'З', 'И', '?', 'К', 'Л', '?', 'М', 'Н', '?', 'О', 'П', 'Р', 'С', 'Т', '?', 'У', 'Ф', 'Х', 'Ц', 'Ч', '?', 'Ш',
'а', 'б', 'в', 'г', 'д', '?', 'е', 'ж', 'з', 'и', '?', 'к', 'л', '?', 'м', 'н', '?', 'о', 'п', 'р', 'с', 'т', '?', 'у', 'ф', 'х', 'ц', 'ч', '?', 'ш',
'Ё', 'Й', 'Ц', 'У', 'К', 'Е', 'Н', 'Г', 'Ш', 'Щ', 'З', 'Х', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я',
'ё', 'й', 'ц', 'у', 'к', 'е', 'н', 'г', 'ш', 'щ', 'з', 'х', 'ъ', 'ы', 'ь', 'э', 'ю', 'я'
);
$latinica = array(
'A', 'B', 'V', 'G', 'D', '?', 'E', '?', 'Z', 'I', 'J', 'K', 'L', 'Lj', 'M', 'N', 'Nj', 'O', 'P', 'R', 'S', 'T', '?', 'U', 'F', 'H', 'C', '?', 'D?', '?',
'a', 'b', 'v', 'g', 'd', '?', 'e', '?', 'z', 'i', 'j', 'k', 'l', 'lj', 'm', 'n', 'nj', 'o', 'p', 'r', 's', 't', '?', 'u', 'f', 'h', 'c', '?', 'd?', '?',
'Yo', 'J', 'C', 'U', 'K', 'E', 'N', 'G', 'Sh', 'Shch', 'Z', 'Kh', '"', 'Y', "'", 'E', 'Yu', 'Ya',
'yo', 'j', 'c', 'u', 'k', 'e', 'n', 'g', 'sh', 'shch', 'z', 'kh', '"', 'y', "'", 'e', 'yu', 'ya'
);
return str_replace($cirilica, $latinica, $text);
}
// Apply transliteration to WooCommerce AJAX fragments (e.g., mini-cart)
function transliterate_ajax_fragments($fragments) {
foreach ($fragments as &$fragment) {
$fragment = cir_to_lat($fragment);
}
return $fragments;
}
add_filter('woocommerce_add_to_cart_fragments', 'transliterate_ajax_fragments');
// Apply transliteration to WooCommerce currency symbol and currency text
function transliterate_currency_symbol($currency_symbol, $currency) {
return cir_to_lat($currency_symbol);
}
add_filter('woocommerce_currency_symbol', 'transliterate_currency_symbol', 10, 2);
// Apply transliteration to WooCommerce email content, subject, and heading
function transliterate_woocommerce_email_content($content) {
return cir_to_lat($content);
}
add_filter('woocommerce_email_content', 'transliterate_woocommerce_email_content');
add_filter('woocommerce_email_subject', 'transliterate_woocommerce_email_content');
add_filter('woocommerce_email_heading', 'transliterate_woocommerce_email_content');
// Apply transliteration to gettext strings (including currency)
function transliterate_woocommerce_strings($translated_text, $text, $domain) {
return cir_to_lat($translated_text);
}
add_filter('gettext', 'transliterate_woocommerce_strings', 10, 3);
add_filter('gettext_with_context', 'transliterate_woocommerce_strings', 10, 3);
// Apply transliteration on wp_mail for broader coverage on all email content
function transliterate_wp_mail($args) {
$args['message'] = cir_to_lat($args['message']);
return $args;
}
add_filter('wp_mail', 'transliterate_wp_mail');
// Transliteracija na latinicu pre nego ?to HTML bude prikazan
function transliterate_html_output($buffer) {
return cir_to_lat($buffer);
}
// Start output buffering to apply transliteration to the entire HTML content
function start_transliteration_buffer() {
ob_start('transliterate_html_output');
}
function end_transliteration_buffer() {
ob_end_flush();
}
add_action('wp_loaded', 'start_transliteration_buffer');
add_action('shutdown', 'end_transliteration_buffer');
// Ensure email is resent in Latin by applying transliteration
add_action('woocommerce_before_resend_order_emails', function() {
add_filter('woocommerce_email_content', 'transliterate_woocommerce_email_content');
});
// Apply transliteration specifically in WooCommerce Admin
function transliterate_woocommerce_admin_text($translated_text, $text, $domain) {
// Only apply within WooCommerce admin screens
if (is_admin() && isset($_GET['post_type']) && $_GET['post_type'] === 'shop_order') {
return cir_to_lat($translated_text);
}
return $translated_text;
}
add_filter('gettext', 'transliterate_woocommerce_admin_text', 10, 3);
add_filter('gettext_with_context', 'transliterate_woocommerce_admin_text', 10, 3);
// Transliterate WooCommerce currency symbol in Admin
function transliterate_admin_currency_symbol($currency_symbol, $currency) {
if (is_admin()) {
return cir_to_lat($currency_symbol);
}
return $currency_symbol;
}
add_filter('woocommerce_currency_symbol', 'transliterate_admin_currency_symbol', 10, 2);
// Force transliteration on manual emails sent via WooCommerce
function transliterate_manual_woocommerce_emails($email) {
$email->subject = cir_to_lat($email->subject);
$email->heading = cir_to_lat($email->heading);
$email->content = cir_to_lat($email->content);
}
add_action('woocommerce_email', 'transliterate_manual_woocommerce_emails');
// Apply transliteration in Admin using output buffering
function start_admin_transliteration_buffer() {
if (is_admin()) {
ob_start('transliterate_html_output');
}
}
function end_admin_transliteration_buffer() {
if (is_admin()) {
ob_end_flush();
}
}
add_action('admin_init', 'start_admin_transliteration_buffer');
add_action('shutdown', 'end_admin_transliteration_buffer');The page I need help with: [log in to see the link]
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- You must be logged in to reply to this topic.