Skip Navigation

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

Problem:
You are trying to translate WooCommerce product attributes for different products where the attribute 'Size' has numerical values. However, these values are not appearing in the Translation Editor, and the WooCommerce > WooCommerce Multilingual > Attributes tab is empty because the attributes were set manually and not as global attributes.

Solution:
To translate numerical values in product attributes, you need to add a specific code snippet to the functions.php file of your theme. Here is the code you should add:

function wpmlsupp_7499_allow_translating_numbers($is_translatable, $job_translate) {<br />    $data = $job_translate['field_data'];<br />    if ('base64' === $job_translate['field_format']) {<br />        $data = base64_decode($data);<br />    }<br />    if (is_numeric($data)) {<br />        return true;<br />    }<br />    return $is_translatable;<br />}<br />add_filter('wpml_tm_job_field_is_translatable', 'wpmlsupp_7499_allow_translating_numbers', 10, 2);

After adding this code, make a minor change to the product, save it, and update the translation. In the Translation Editor, manually search for the number you wish to translate. Ensure that the translation preference for the field where you're adding the numerical value is set to 'Translatable' in WPML > Settings > Custom Field translation.

If you're using custom attributes not created through the WooCommerce > Attributes section, consider creating global attributes for easier management and translation.

If this solution does not resolve your issue or seems outdated, we recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If needed, please open a new support ticket at WPML support forum for further assistance.

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.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Prosenjit Barman 3 months ago.

Assisted by: Prosenjit Barman.

Author Posts
September 19, 2024 at 1:05 pm #16198894

kolosD

Background of the issue:
I'm trying to translate Woocommerce product attributes. I have product 'A' and product 'B' both with the attribute called 'Size' and its value is '2' (just the number). I want to translate both products, the product 'A' size value to '2', but the product 'B' size value to '3'.

Symptoms:
The attribute value is not showing in the Translation Editor.

Questions:
How can I translate Woocommerce product attributes with WPML?
Why is the attribute value not showing in the Translation Editor?

September 20, 2024 at 7:17 am #16201433

Prosenjit Barman
Supporter

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hello There,
Thanks for contacting WPML Support.

I understand that you want to translate the WooCommerce attributes. Typically, the attribute terms appear in the translation editor when translating the product. However, you can also translate the attribute terms by navigating to WooCommerce > WooCommerce Multilingual > Attributes tab. Since you're looking to translate the number, it's best to do so from the WooCommerce > WooCommerce Multilingual > Attributes tab.

However, if you want to translate the numerical values from the ATE, you'll need to add the following code snippet to the functions.php file of your theme first.

function wpmlsupp_7499_allow_translating_numbers( $is_translatable, $job_translate ) {
    $data = $job_translate['field_data'];
	if ( 'base64' === $job_translate['field_format'] ) {
		$data = base64_decode( $data );
	}
    if ( is_numeric( $data ) ) {
    	return true;
    }
    return $is_translatable;
}
add_filter( 'wpml_tm_job_field_is_translatable', 'wpmlsupp_7499_allow_translating_numbers', 10, 2 );

Once you've added the code, make a small change to the product, save the changes, and then proceed to update the translation. In the translation editor, search for the number you want to translate, and it should appear there.

[Please make sure that the translation preference for the field where you're adding the numerical value is set to `Translatable` in WPML > Settings > Custom Field translation]

I hope the information above helps. Please feel free to let me know if you need further assistance or clarification. I will be happy to help.

Best regards,
Prosenjit

September 20, 2024 at 7:36 am #16201467

kolosD

Hi!

The WooCommerce > WooCommerce Multilingual > Attributes tab is empty. Maybe because I set the attributes manually and not global attributes?

I added the code and also cleared the cache, nothing changed.

kolosD

September 23, 2024 at 3:25 am #16207177

Prosenjit Barman
Supporter

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hello kolosD,
I hope you're doing well. Sorry for the delay in responding due to the weekend.

If you're using custom attributes not created through the WooCommerce > Attributes section, the Attributes tab in WooCommerce Multilingual will show up empty. We always recommend creating global attributes, as they are easier to manage.

However, after adding the code, you'll need to resend the product for translation. During the process, the number won't automatically appear in the translation editor. You'll need to search for it manually. Please make sure you've entered the number you're trying to translate into the search box within the translation editor.

If you're still unable to translate the number, please try creating a global attribute and translating the number from there to see if it meets your requirements.

Please let me know how it goes. I'll be happy to help if you need further assistance in this matter.

Best regards,
Prosenjit

September 23, 2024 at 11:46 am #16209290

kolosD

After searching for the number in the search bar, the option to translate the number appeared.

Thank you for the help!