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 5 replies, has 2 voices.

Last updated by Riffaz 2 months ago.

Assigned support staff: Riffaz.

Author Posts
August 19, 2019 at 8:47 am #4414719

Vasileios Chouliaras

Hi.

I use the Code Snippet plugin to add some custom code.

I would like to work with the following snippet

// Minimum Phone numbers digits
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');

function my_custom_checkout_field_process() {
global $woocommerce;

// Check if set, if its not set add an error. This one is only requite for companies
if ( ! (preg_match('/^[0-9 \-]{10}/i', $_POST['billing_phone'] ))){
wc_add_notice(__('Incorrect Phone Number! Please enter valid phone number', 'barberry'), 'error');
}
}

Snippet works ok but i can't find the "Incorrect Phone Number! Please enter valid phone number" to translate it at string translation. 'barberry' is the text domain of my theme. I search it for strings but this message doesn't appear there for translation. Also i scanned the code snippet plugin but nothing also.

Any help?
Thanks

August 19, 2019 at 11:32 am #4415561

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Thank you for contacting WPML support.

You are adding this in your functions.php right?
you have to scan the theme files (parent/child according to what you are using)
Please follow the steps: https://wpml.org/documentation/getting-started-guide/theme-localization/#scanning-themes-for-texts

Then go to WPML > String Translation
search the text
you will be able to find it.

Let me know how it goes.

Regards,
Riffaz.

August 19, 2019 at 12:15 pm #4415815

Vasileios Chouliaras

Hi. Thanks for your reply. I tested it with function.php of child and works.

But how could i make it work with Code Snippet plugin?
It helps because i can control it with one click.

Thanks

August 20, 2019 at 6:29 am #4420745

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

I am not sure what do you mean by that.
WPML is only for translating. Not for anything else.

But how could i make it work with Code Snippet plugin?
- I do not understand this.
- if you are asking about changing or implementing some custom code that is out of the support scope.

Let me know if you need anything else regarding this.

Regards,

August 20, 2019 at 7:54 am #4421217

Vasileios Chouliaras

Hello.
Code snippet is a plugin that you can add custom code and work with this.
Instead of add the code to function.php or css under the theme css.
You can add your code there and work with it.

And when you dont want the code anymore you can disable it with one click.
That's why this is helpful.

And i wondering if possible to make this code translatable.
What i have to search?
If this is a problem i will work with function.php

Thanks

August 20, 2019 at 11:29 am #4423153

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

It does not matter how you are using the code.
If you follow the procedure to make the strings translatable, then you should be able to translate it in WPML > String Translation.
If not, that means you are making some mistakes in the 'gettext' format:
1. https://wpml.org/faq/getting-string-translation-to-work/
2. https://codex.wordpress.org/I18n_for_WordPress_Developers#Introduction_to_Gettext

Regards,

The topic ‘[Closed] Translate custom snippet code’ is closed to new replies.