Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're trying to translate custom text on your product page that is added through code snippets, like delivery time options and messages, and you're unsure how to make these texts translatable with WPML.

Solution:
First, we recommend scanning the plugin where you added the custom code in WPML -> Theme and plugins localization. After scanning, you should look for the strings in WPML -> String Translation and translate them there. Here are some guides to assist you:

Additionally, check out these guides on how to register custom strings properly with WPML:

If this solution doesn't seem relevant to your situation, please don't hesitate to open a new support ticket with us.
WPML Support Forum

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 1 reply, has 2 voices.

Last updated by Waqas Bin Hasan 1 year, 7 months ago.

Assisted by: Waqas Bin Hasan.

Author Posts
November 1, 2023 at 5:26 pm #14709407

danielK-87

Hello,

I am trying to translate custom text on my product page, like here:hidden link

Text is made in code snippets and code looks following :

add_action('woocommerce_product_options_general_product_data', 'add_custom_field_product_delivery');
function add_custom_field_product_delivery() {
echo '<div class="product_custom_field">';
woocommerce_wp_select(
array(
'id' => 'delivery_time',
'label' => __('Delivery Time', 'woocommerce'),
'options' => array(
'0' => __('Nie pokazuj', 'woocommerce'),
'3' => __('3 dni robocze', 'woocommerce'),
'8' => __('8 dni roboczych', 'woocommerce'),
'30' => __('30 dni roboczych', 'woocommerce')
)
)
);
echo '</div>';
}

add_action('woocommerce_process_product_meta', 'save_custom_field_product_delivery');
function save_custom_field_product_delivery($post_id) {
$delivery_time = isset($_POST['delivery_time']) ? $_POST['delivery_time'] : '';
update_post_meta($post_id, 'delivery_time', sanitize_text_field($delivery_time));
}

add_action('woocommerce_before_add_to_cart_form', 'custom_delivery_date_message', 20);
function custom_delivery_date_message() {
date_default_timezone_set('Europe/Warsaw');
$currentDateTime = new DateTime();
$currentDayOfWeek = $currentDateTime->format('N');
$currentHour = $currentDateTime->format('G');
$deliveryDays = get_post_meta(get_the_ID(), 'delivery_time', true);

if ($deliveryDays == 0) {
return; // Jeśli wybrano "Nie pokazuj", nie wyświetlaj komunikatu
}

$deliveryDate = new DateTime();
$deadlineHour = 11;

// Jeśli aktualna godzina jest późniejsza niż godzina graniczna, dodajemy dodatkowy dzień do dostawy
if ($currentHour >= $deadlineHour) {
$deliveryDate->modify('+1 day');
}

for ($i = 0; $i < $deliveryDays; $i++) {
$deliveryDate->modify('+1 day');
// Jeśli to jest weekend, dodajemy dodatkowy dzień
if ($deliveryDate->format('N') >= 6) {
$i--;
}
}

setlocale(LC_TIME, 'pl_PL.utf8');
echo '<div class="custom-delivery-message"><p>🚚 Zamów teraz, a zamówienie wyślemy: <span style="font-weight:800; color:#36b4e4;">' . strftime('%A (%d.%m)', $deliveryDate->getTimestamp()) . '</span></p></div>';
}

What I need to add here to register new strings or maybe is there another way to translate this text.
Many thanks in advance for your support.

Best Regards
Daniel

Zrzut ekranu 2023-11-1 o 18.24.46.png
November 2, 2023 at 12:30 pm #14716441

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Daniel,

Thank you for contacting the support.

Generally we do not provide support for custom coding in this forum, but, I'll advise to scan the said plugin (where you added the code) in WPML -> Theme and plugins localization. Then you should search for the strings in WPML -> String Translation and translate accordingly.

Please see following guides for more information:

- https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/
- https://wpml.org/documentation/getting-started-guide/string-translation/

Besides this, I'll also suggest to check the following guides about registering custom strings properly with WPML:

- https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/
- https://wpml.org/documentation/support/translating-the-theme-you-created/

Regards.