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 0 voices.

Last updated by myleneG 1 month, 3 weeks ago.

Assisted by: Otto.

Author Posts
October 3, 2025 at 1:12 pm #17454507

myleneG

Background of the issue:
I am trying to localize a functions snippet for my site hidden link. The snippet involves a filter for 'woocommerce_shipping_package_name' and a function 'change_shipping_text_to_delivery' that modifies the shipping text to delivery options. The code snippet is: add_filter('woocommerce_shipping_package_name', 'change_shipping_text_to_delivery', 20, 3 ); function change_shipping_text_to_delivery( $sprintf, $i, $package ) { $sprintf = sprintf( _nx( 'Options de livraison (ajouter 1 à 2 jours de manutention.)', 'Delivery %d', ( $i + 1 ), 'delivery packages', 'woocommerce' ), ( $i + 1 ) ); return $sprintf; }

Symptoms:
I need help with localizing the snippet for my WordPress site.

Questions:
How can I localize the given functions snippet to make it translatable?
add_filter('woocommerce_shipping_package_name', 'change_shipping_text_to_delivery', 20, 3 );
function change_shipping_text_to_delivery( $sprintf, $i, $package ) {
$sprintf = sprintf( _nx( _e('Options de livraison (ajouter 1 à 2 jours de manutention.),'woocommerce'), 'Delivery %d', ( $i + 1 ), 'delivery packages', 'woocommerce' ), ( $i + 1 ) );
return $sprintf;
}

October 3, 2025 at 3:51 pm #17454946

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Take a looks at this documentation please:
https://wpml.org/documentation/support/how-to-use-gettext

Then follow these steps:
❌ Please make a full website backup before proceeding ❌

Step 1: Replace your snippet with a gettext-ready version using your child theme text-domain (e.g. funique-child or similar).

add_filter( 'woocommerce_shipping_package_name', function( $title, $i, $package ) {
    /* translators: %d is the sequential package number starting at 1 */
    $pattern = esc_html_x( 'Delivery %d', 'shipping package title', 'funique-child' );
    return sprintf( $pattern, $i + 1 );
}, 20, 3 );

Why: WPML will scan your child theme and register Delivery %d under your domain instead of “woocommerce”.

Step 2: WP Admin → WPML → Theme and plugins localization → scan your child theme.

Step 3: WP Admin → WPML → String Translation → find domain funique-child, translate “Delivery %d” into French (you can drop %d if you don’t need the number, the extra sprintf arg is safely ignored):
Options de livraison (ajouter 1 à 2 jours de manutention.)

Step 4 (optional): If the string doesn’t appear, enable Auto register strings temporarily and reload the cart/checkout once, then translate it:
https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/

Best Regards,
Otto

October 3, 2025 at 6:29 pm #17455204

myleneG

Thank you very much, I had trouble with step 1!