Skip to content Skip to sidebar

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 Dražen 1 year, 10 months ago.

Author Posts
September 21, 2023 at 10:47 am #14437513

julienS-26

Hi,

I add a custom snippet with WPCode Snippet plugin which is:

add_action( 'wp_footer', 'wc_modify_variation_atc_text' );
function wc_modify_variation_atc_text() {
?>
<script type="text/javascript">
(function( $ ) {
var $form = $( '.product form.variations_form' );
$form.find( '.single_add_to_cart_button' ).html('Sélectionner une longueur');
$form.on( 'show_variation', function( event, variation, purchasable ) {
$form.find( '.single_add_to_cart_button' ).html('Ajouter au panier');
} );
} )( jQuery );
</script>
<?php
}

I changed text from add to cart button for variable product before customer select variant then the button back to text "add to cart".

How can I add string to these? I need to translate "Sélectionner une longueur" (select lenght) and "Ajouter au panier" (add to cart)

Thanks a lot !!

September 21, 2023 at 12:43 pm #14439153

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi there.

Please make sure you are following our guides and also that you are following WordPress's instructions on how to localize scripts.

- https://developer.wordpress.org/reference/functions/wp_localize_script/

- https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/

I would rather suggest implementing changes via PHP hooks and translating them as regular strings.

Also, please note that we currently are not able to provide support for custom work within this forum which will be required for translating something from inside Javascript. I, however, tried to point you in the correct direction.

If my directions are not enough I suggest contacting one of our 3rd party contractors that specialize in custom work with WPML (https://wpml.org/contractors/) or a developer of your choice.

I hope that you will find this answer insightful.

Let us know if any other questions or anything we can do to help.

Regards,
Drazen

The topic ‘[Closed] Translation of code snippet’ is closed to new replies.